Salome HOME
5f56add8f6b6f36327723b5e0dcd1a479b0c7679
[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 //
23 //
24 //  File   : SMESHGUI.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_AddHypothesisDlg.h"
32 #include "SMESHGUI_AddAlgorithmDlg.h"
33 #include "SMESHGUI_InitMeshDlg.h"
34 #include "SMESHGUI_LocalLengthDlg.h"
35 #include "SMESHGUI_NbSegmentsDlg.h"
36 #include "SMESHGUI_AddSubMeshDlg.h"
37 #include "SMESHGUI_NodesDlg.h"
38 #include "SMESHGUI_TransparencyDlg.h"
39 #include "SMESHGUI_RemoveNodesDlg.h"
40 #include "SMESHGUI_RemoveElementsDlg.h"
41 #include "SMESHGUI_MeshInfosDlg.h"
42 #include "SMESHGUI_Preferences_ColorDlg.h"
43 #include "SMESHGUI_MaxElementAreaDlg.h"
44 #include "SMESHGUI_MaxElementVolumeDlg.h"
45 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
46 #include "SMESHGUI_EditScalarBarDlg.h"
47 #include "SMESHGUI_aParameterDlg.h"
48 #include "SMESHGUI_ComputeScalarValue.h"
49 #include "SMESHGUI_MoveNodesDlg.h"
50 #include "SMESHGUI_OrientationElementsDlg.h"
51 #include "SMESHGUI_DiagonalInversionDlg.h"
52 #include "SMESHGUI_EdgesConnectivityDlg.h"
53 #include "SMESHGUI_AddFaceDlg.h"
54 #include "SMESHGUI_AddEdgeDlg.h"
55 #include "SMESHGUI_AddVolumeDlg.h"
56 #include "SMESHGUI_EditHypothesesDlg.h"
57
58 #include "SMESH_Grid.h"
59
60 // SALOME Includes
61 #include "Utils_ORB_INIT.hxx"
62 #include "Utils_SINGLETON.hxx"
63
64 #include "QAD.h"
65 #include "QAD_Tools.h"
66 #include "QAD_Config.h"
67 #include "QAD_Settings.h"
68 #include "QAD_RightFrame.h"
69 #include "QAD_MessageBox.h"
70 #include "QAD_Resource.h"
71 #include "QAD_FileDlg.h"
72 #include "SALOMEGUI_Desktop.h"
73 #include "SALOMEGUI_NameDlg.h"
74
75 #include "OCCViewer_ViewPort.h"
76 #include "OCCViewer_ViewPort3d.h"
77 #include "OCCViewer_Viewer3d.h"
78
79 #include "GEOM_Client.hxx"
80 #include "GEOM_InteractiveObject.hxx"
81
82 #include "SALOME_NamingService.hxx"
83 #include "SALOME_ListIteratorOfListIO.hxx"
84 #include "SALOME_InteractiveObject.hxx"
85
86 #include "SALOMEGUI_ImportOperation.h"
87 #include "SALOMEGUI_QtCatchCorbaException.hxx"
88 #include "utilities.h"
89
90 #include "SMDS_Mesh.hxx"
91 #include "SMESHDS_Document.hxx"
92 #include "Document_Reader.h"
93 #include "Document_Writer.h"
94 #include "Mesh_Reader.h"
95 #include "Mesh_Writer.h"
96
97 #include "DriverDAT_R_SMESHDS_Document.h"
98 #include "DriverMED_R_SMESHDS_Document.h"
99 #include "DriverUNV_R_SMESHDS_Document.h"
100 #include "DriverDAT_W_SMESHDS_Document.h"
101 #include "DriverMED_W_SMESHDS_Document.h"
102 #include "DriverUNV_W_SMESHDS_Document.h"
103 #include "DriverDAT_R_SMESHDS_Mesh.h"
104 #include "DriverMED_R_SMESHDS_Mesh.h"
105 #include "DriverUNV_R_SMESHDS_Mesh.h"
106 #include "DriverDAT_W_SMESHDS_Mesh.h"
107 #include "DriverMED_W_SMESHDS_Mesh.h"
108 #include "DriverUNV_W_SMESHDS_Mesh.h"
109
110 // QT Includes
111 #define  INCLUDE_MENUITEM_DEF
112 #include <qapplication.h>
113 #include <qlineedit.h>
114 #include <qmenudata.h>
115 #include <qmenubar.h>
116 #include <qpopupmenu.h>
117 #include <qfont.h>
118 #include <qstring.h>
119 #include <qcheckbox.h>
120 #include <qcolordialog.h>
121 #include <qmessagebox.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 <vtkLegendBoxActor.h>
132 #include <vtkFeatureEdges.h>
133 #include <vtkDoubleArray.h>
134
135 // Open CASCADE Includes
136 #include <gp_Pnt.hxx>
137 #include <gp_Vec.hxx>
138
139 static GEOM_Client ShapeReader;
140 static SMESHGUI *smeshGUI = 0;
141 static CORBA::ORB_var _orb;
142
143 //=============================================================================
144 /*!
145  *
146  */
147 //=============================================================================
148 class CustomItem:public QCustomMenuItem
149 {
150   public:
151         CustomItem(const QString & s, const QFont & f):string(s), font(f)
152         {
153         };
154         ~CustomItem()
155         {
156         }
157
158         void paint(QPainter * p, const QColorGroup & /*cg */ , bool /*act */ ,
159                 bool /*enabled */ , int x, int y, int w, int h)
160         {
161                 p->setFont(font);
162                 p->drawText(x, y, w, h,
163                         AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
164         }
165
166         QSize sizeHint()
167         {
168                 return QFontMetrics(font).
169                         size(AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
170         }
171   private:
172         QString string;
173         QFont font;
174 };
175
176 //=============================================================================
177 /*!
178  *
179  */
180 //=============================================================================
181 SMESHGUI::SMESHGUI():
182 QObject()
183 {
184 }
185
186 //=============================================================================
187 /*!
188  *
189  */
190 //=============================================================================
191 SMESHGUI::~SMESHGUI()
192 {
193 }
194
195 //=============================================================================
196 /*!
197  *
198  */
199 //=============================================================================
200 SMESHGUI *SMESHGUI::GetSMESHGUI()
201 {
202         return smeshGUI;
203 }
204
205 //=============================================================================
206 /*!
207  *
208  */
209 //=============================================================================
210 SMESHGUI *SMESHGUI::GetOrCreateSMESHGUI(QAD_Desktop * desktop)
211 {
212         if (smeshGUI == 0)
213         {
214                 setOrb();
215                 smeshGUI = new SMESHGUI;
216                 smeshGUI->myActiveDialogBox = 0;
217                 smeshGUI->myState = -1;
218                 smeshGUI->myDesktop = desktop;
219                 smeshGUI->myActiveStudy = desktop->getActiveStudy();
220
221                 Engines::Component_var comp =
222                         desktop->getEngine("FactoryServer", "SMESH");
223                 smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
224
225                 Engines::Component_var comp1 =
226                         desktop->getEngine("FactoryServer", "GEOM");
227                 smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
228
229                 /* GetCurrentStudy */
230                 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
231
232                 smeshGUI->myComponentGeom->GetCurrentStudy(smeshGUI->myStudyId);
233                 //    smeshGUI->myComponentGeom->NbLabels();
234
235                 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
236
237                 smeshGUI->myStudyAPI =
238                         SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
239
240                 smeshGUI->myDocument = new SMESHDS_Document(1); //NBU
241
242                 smeshGUI->mySimulationActors = vtkActorCollection::New();
243                 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
244         }
245         else
246         {
247                 /* study may have changed */
248                 smeshGUI->myActiveStudy = desktop->getActiveStudy();
249                 smeshGUI->myStudyAPI.Update(smeshGUI->myComponentMesh);
250         }
251
252         /* Automatic Update */
253         if (desktop->menuBar()->isItemChecked(1001))
254                 smeshGUI->myAutomaticUpdate = true;
255         else
256                 smeshGUI->myAutomaticUpdate = false;
257
258         return smeshGUI;
259 }
260
261 //=============================================================================
262 /*!
263  *
264  */
265 //=============================================================================
266 void SMESHGUI::SetState(int aState)
267 {
268         this->myState = aState;
269         return;
270 }
271
272 //=============================================================================
273 /*!
274  *
275  */
276 //=============================================================================
277 void SMESHGUI::ResetState()
278 {
279         this->myState = -1;
280         return;
281 }
282
283 //=============================================================================
284 /*!
285  *
286  */
287 //=============================================================================
288 void SMESHGUI::EmitSignalDeactivateDialog()
289 {
290         emit this->SignalDeactivateActiveDialog();
291         return;
292 }
293
294 //=============================================================================
295 /*!
296  *
297  */
298 //=============================================================================
299 void SMESHGUI::EmitSignalCloseAllDialogs()
300 {
301         emit this->SignalCloseAllDialogs();
302         return;
303 }
304
305 //=============================================================================
306 /*!
307  *
308  */
309 //=============================================================================
310 QDialog *SMESHGUI::GetActiveDialogBox()
311 {
312         return this->myActiveDialogBox;
313 }
314
315 //=============================================================================
316 /*!
317  *
318  */
319 //=============================================================================
320 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
321 {
322         this->myActiveDialogBox = (QDialog *) aDlg;
323         return;
324 }
325
326 //=============================================================================
327 /*!
328  *
329  */
330 //=============================================================================
331 QAD_Study *SMESHGUI::GetActiveStudy()
332 {
333         return this->myActiveStudy;
334 }
335
336 //=============================================================================
337 /*!
338  *
339  */
340 //=============================================================================
341 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
342 {
343         return SALOMEDS::Study::_narrow(myStudy);
344 }
345
346 //=============================================================================
347 /*!
348  *
349  */
350 //=============================================================================
351 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
352 {
353         return myStudyAPI;
354 }
355
356 //=============================================================================
357 /*!
358  *
359  */
360 //=============================================================================
361 QAD_Desktop *SMESHGUI::GetDesktop()
362 {
363         return this->myDesktop;
364 }
365
366 //=============================================================================
367 /*!
368  *
369  */
370 //=============================================================================
371 vtkScalarBarActor *SMESHGUI::GetScalarBar()
372 {
373         vtkRenderer *aRenderer =
374                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
375                 getRightFrame()->getViewFrame())->getRenderer();
376         vtkActor2DCollection *actor2DList = aRenderer->GetActors2D();
377         actor2DList->InitTraversal();
378         vtkActor2D *aActor2d = actor2DList->GetNextActor2D();
379         while (aActor2d != NULL)
380         {
381                 if (aActor2d->IsA("vtkScalarBarActor"))
382                         return vtkScalarBarActor::SafeDownCast(aActor2d);
383                 actor2DList->GetNextActor2D();
384         }
385         return NULL;
386 }
387
388 //=============================================================================
389 /*!
390  *
391  */
392 //=============================================================================
393 void SMESHGUI::activeStudyChanged(QAD_Desktop * parent)
394 {
395         MESSAGE("SMESHGUI::activeStudyChanged init.")
396                 /* Create or retrieve an object SMESHGUI */
397                 SMESHGUI::GetOrCreateSMESHGUI(parent);
398         if (smeshGUI != 0)
399         {
400                 smeshGUI->EmitSignalCloseAllDialogs();
401                 MESSAGE("Active study changed : SMESHGUI nullified" << endl);
402                 smeshGUI = 0;
403         }
404
405         //smeshGUI->SetSettings( parent ); //DCQ : Pb. Multi-Etudes
406         MESSAGE("SMESHGUI::activeStudyChanged done.") return;
407 }
408
409 //=============================================================================
410 /*!
411  *
412  */
413 //=============================================================================
414 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
415 {
416         /* Here the position is on the bottom right corner - 10 */
417         aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
418         QAD_Desktop *PP = QAD_Application::getDesktop();
419         x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
420         y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
421         return true;
422 }
423
424 //=============================================================================
425 /*!
426  *
427  */
428 //=============================================================================
429 void SMESHGUI::EraseSimulationActors()
430 {
431         if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
432         {                                                       //VTK
433                 vtkRenderer *theRenderer =
434                         ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
435                         getRightFrame()->getViewFrame())->getRenderer();
436                 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
437
438                 if (mySimulationActors != NULL)
439                 {
440
441                         mySimulationActors->InitTraversal();
442                         vtkActor *ac = mySimulationActors->GetNextActor();
443                         while (!(ac == NULL))
444                         {
445                                 theRenderer->RemoveActor(ac);
446                                 ac = mySimulationActors->GetNextActor();
447                         }
448                         mySimulationActors->RemoveAllItems();
449                 }
450                 if (mySimulationActors2D != NULL)
451                 {
452                         mySimulationActors2D->InitTraversal();
453                         vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
454                         while (!(ac == NULL))
455                         {
456                                 theRenderer->RemoveActor2D(ac);
457                                 ac = mySimulationActors2D->GetNextActor2D();
458                         }
459                         mySimulationActors2D->RemoveAllItems();
460                 }
461                 renWin->Render();
462         }
463 }
464
465 //=============================================================================
466 /*!
467  *
468  */
469 //=============================================================================
470 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh(GEOM::GEOM_Shape_ptr aShape,
471         QString NameMesh)
472 {
473         try
474         {
475                 if (!myComponentMesh->_is_nil() && !aShape->_is_nil())
476                 {
477                         SMESH::SMESH_Mesh_var aMesh =
478                                 myComponentMesh->Init(myComponentGeom, myStudyId, aShape);
479
480                         if (!aMesh->_is_nil())
481                         {
482                                 SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh(aMesh);
483                                 myStudyAPI.SetName(SM, NameMesh);
484
485                                 // GEOM::GEOM_Shape has non-empty StudyShapeId only after AddInStudy operation,
486                                 // not after loading from file, so let's use more reliable way to retrieve SObject
487                                 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
488                                 SALOMEDS::SObject_var SObject =
489                                         myStudy->FindObjectIOR(ShapeIOR);
490                                 if (!SObject->_is_nil() && !SM->_is_nil())
491                                 {
492                                         myStudyAPI.SetShape(SM, SObject);
493                                 }
494                                 return SMESH::SMESH_Mesh::_narrow(aMesh);
495                         }
496                 }
497         }
498         catch(const SALOME::SALOME_Exception & S_ex)
499         {
500                 QtCatchCorbaException(S_ex);
501         }
502         myActiveStudy->updateObjBrowser(true);
503         return SMESH::SMESH_Mesh::_nil();
504 }
505
506 //=============================================================================
507 /*!
508  *
509  */
510 //=============================================================================
511 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh(SMESH::SMESH_Mesh_ptr aMesh,
512         GEOM::GEOM_Shape_ptr aShape, QString NameMesh)
513 {
514         try
515         {
516                 SMESH::SMESH_subMesh_var aSubMesh = aMesh->GetElementsOnShape(aShape);
517                 SALOMEDS::SObject_var SO_Mesh = myStudyAPI.FindMesh(aMesh);
518                 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
519                 SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectIOR(ShapeIOR);
520
521                 if (!SO_GeomShape->_is_nil() && !SO_Mesh->_is_nil() &&
522                         !aSubMesh->_is_nil() && !aMesh->_is_nil())
523                 {
524                         SALOMEDS::SObject_var SO =
525                                 myStudyAPI.AddSubMeshOnShape(SO_Mesh, SO_GeomShape, aSubMesh,
526                                 aShape->ShapeType());
527                         myStudyAPI.SetName(SO, NameMesh);
528
529                         SMESH_Actor *amesh = SMESH_Actor::New();
530                         Handle(SALOME_InteractiveObject) IO =
531                                 new SALOME_InteractiveObject(SO->GetID(), "MESH",
532                                 strdup(NameMesh));
533                         amesh->setIO(IO);
534                         amesh->setName(strdup(NameMesh));
535                         DisplayActor(amesh, false);
536                         return SMESH::SMESH_subMesh::_narrow(aSubMesh);
537                 }
538         }
539         catch(const SALOME::SALOME_Exception & S_ex)
540         {
541                 QtCatchCorbaException(S_ex);
542         }
543         myActiveStudy->updateObjBrowser(true);
544         return SMESH::SMESH_subMesh::_nil();
545 }
546
547 //=============================================================================
548 /*!
549  *
550  */
551 //=============================================================================
552 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis(QString TypeHypothesis,
553         QString NameHypothesis)
554 {
555         SMESH::SMESH_Hypothesis_var Hyp;
556         try
557         {
558                 Hyp = myComponentMesh->CreateHypothesis(TypeHypothesis, myStudyId);
559                 if (!Hyp->_is_nil())
560                 {
561                         SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewHypothesis(Hyp);
562                         myStudyAPI.SetName(SHyp, NameHypothesis);
563                 }
564         }
565         catch(const SALOME::SALOME_Exception & S_ex)
566         {
567                 QtCatchCorbaException(S_ex);
568         }
569
570         return SMESH::SMESH_Hypothesis::_narrow(Hyp);
571 }
572
573 //=============================================================================
574 /*!
575  *
576  */
577 //=============================================================================
578 void SMESHGUI::AddHypothesisOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
579         SMESH::SMESH_Hypothesis_ptr aHyp)
580 {
581         if (!aMesh->_is_nil())
582         {
583                 QApplication::setOverrideCursor(Qt::waitCursor);
584                 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
585                 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
586                 try
587                 {
588                         bool res = aMesh->AddHypothesis(aShape, aHyp);
589                         if (res)
590                         {
591                                 SALOMEDS::SObject_var SH =
592                                         myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
593                                 if (!SM->_is_nil() && !SH->_is_nil())
594                                 {
595                                         myStudyAPI.SetHypothesis(SM, SH);
596                                         myStudyAPI.ModifiedMesh(SM, false);
597                                 }
598                                 QApplication::restoreOverrideCursor();
599                         }
600                         else
601                         {
602                                 QApplication::restoreOverrideCursor();
603                                 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
604                                         tr("SMESH_WRN_WARNING"),
605                                         tr("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"),
606                                         tr("SMESH_BUT_YES"));
607                         }
608                 }
609                 catch(const SALOME::SALOME_Exception & S_ex)
610                 {
611                         QtCatchCorbaException(S_ex);
612                 }
613         }
614         myActiveStudy->updateObjBrowser(true);
615         QApplication::restoreOverrideCursor();
616 }
617
618 //=============================================================================
619 /*!
620  *
621  */
622 //=============================================================================
623 void SMESHGUI::
624 RemoveHypothesisOrAlgorithmOnMesh(const Handle(SALOME_InteractiveObject) &
625         IObject)
626 {
627         if (IObject->hasReference())
628         {
629                 SMESH::SMESH_Hypothesis_var anHyp;
630                 SALOMEDS::SObject_var SO_Hypothesis =
631                         smeshGUI->myStudy->FindObjectID(IObject->getEntry());
632                 SALOMEDS::GenericAttribute_var anAttr;
633                 SALOMEDS::AttributeIOR_var anIOR;
634
635                 if (!SO_Hypothesis->_is_nil())
636                 {
637                         QApplication::setOverrideCursor(Qt::waitCursor);
638                         if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR"))
639                         {
640                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
641                                 anHyp =
642                                         SMESH::SMESH_Hypothesis::_narrow(_orb->
643                                         string_to_object(anIOR->Value()));
644                         }
645
646                         SALOMEDS::SObject_var SO_Applied_Hypothesis =
647                                 smeshGUI->myStudy->FindObjectID(IObject->getReference());
648                         if (!SO_Applied_Hypothesis->_is_nil())
649                         {
650                                 SALOMEDS::SObject_var MorSM =
651                                         smeshGUI->myStudyAPI.
652                                         GetMeshOrSubmesh(SO_Applied_Hypothesis);
653                                 if (!MorSM->_is_nil())
654                                 {
655                                         smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
656
657                                         GEOM::GEOM_Shape_var aShape =
658                                                 smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
659                                         if (!aShape->_is_nil())
660                                         {
661                                                 if (MorSM->FindAttribute(anAttr, "AttributeIOR"))
662                                                 {
663                                                         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
664                                                         SMESH::SMESH_Mesh_var aMesh =
665                                                                 SMESH::SMESH_Mesh::_narrow(_orb->
666                                                                 string_to_object(anIOR->Value()));
667                                                         SMESH::SMESH_subMesh_var aSubMesh =
668                                                                 SMESH::SMESH_subMesh::_narrow(_orb->
669                                                                 string_to_object(anIOR->Value()));
670                                                         if (!aMesh->_is_nil())
671                                                         {
672                                                                 bool res =
673                                                                         aMesh->RemoveHypothesis(aShape, anHyp);
674                                                                 if (!res)
675                                                                 {
676                                                                         QApplication::restoreOverrideCursor();
677                                                                         QAD_MessageBox::warn1(QAD_Application::
678                                                                                 getDesktop(), tr("SMESH_WRN_WARNING"),
679                                                                                 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
680                                                                                 tr("SMESH_BUT_YES"));
681                                                                 }
682                                                         }
683                                                         else if (!aSubMesh->_is_nil())
684                                                         {
685                                                                 aMesh = aSubMesh->GetFather();
686                                                                 if (!aMesh->_is_nil())
687                                                                 {
688                                                                         bool res =
689                                                                                 aMesh->RemoveHypothesis(aShape, anHyp);
690                                                                         if (!res)
691                                                                         {
692                                                                                 QApplication::restoreOverrideCursor();
693                                                                                 QAD_MessageBox::warn1(QAD_Application::
694                                                                                         getDesktop(),
695                                                                                         tr("SMESH_WRN_WARNING"),
696                                                                                         tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
697                                                                                         tr("SMESH_BUT_YES"));
698                                                                         }
699                                                                 }
700                                                         }
701                                                         if (myAutomaticUpdate)
702                                                         {
703                                                                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
704                                                                 if (Mesh != NULL)
705                                                                 {
706 #ifdef TRACE
707                                                                         Dump(Mesh);
708 #endif
709                                                                         DisplayActor(Mesh);
710                                                                         DisplayEdges(Mesh);
711                                                                         smeshGUI->ChangeRepresentation(Mesh,
712                                                                                 Mesh->getDisplayMode());
713                                                                 }
714                                                         }
715                                                 }
716                                         }
717                                 }
718                                 smeshGUI->myStudyAPI.UnSetHypothesis(SO_Applied_Hypothesis);
719                         }
720                 }
721         }
722         else if (IObject->hasEntry())
723         {
724         MESSAGE("IObject entry " << IObject->getEntry())}
725         QApplication::restoreOverrideCursor();
726 }
727
728 //=============================================================================
729 /*!
730  *
731  */
732 //=============================================================================
733 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh(SALOMEDS::SObject_ptr MorSM,
734         SMESH::SMESH_Hypothesis_ptr anHyp)
735 {
736         SALOMEDS::SObject_var AHR, aRef;
737         SALOMEDS::GenericAttribute_var anAttr;
738         SALOMEDS::AttributeIOR_var anIOR;
739
740         if (!MorSM->_is_nil())
741         {
742                 GEOM::GEOM_Shape_var aShape =
743                         smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
744                 if (!aShape->_is_nil())
745                 {
746                         if (MorSM->FindAttribute(anAttr, "AttributeIOR"))
747                         {
748                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
749                                 SMESH::SMESH_Mesh_var aMesh =
750                                         SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
751                                                 Value()));
752                                 SMESH::SMESH_subMesh_var aSubMesh =
753                                         SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->
754                                                 Value()));
755                                 if (!aMesh->_is_nil())
756                                 {
757                                         bool res = aMesh->RemoveHypothesis(aShape, anHyp);
758                                         if (!res)
759                                         {
760                                                 QApplication::restoreOverrideCursor();
761                                                 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
762                                                         tr("SMESH_WRN_WARNING"),
763                                                         tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
764                                                         tr("SMESH_BUT_YES"));
765                                         }
766                                 }
767                                 else if (!aSubMesh->_is_nil())
768                                 {
769                                         aMesh = aSubMesh->GetFather();
770                                         if (!aMesh->_is_nil())
771                                         {
772                                                 bool res = aMesh->RemoveHypothesis(aShape, anHyp);
773                                                 if (!res)
774                                                 {
775                                                         QApplication::restoreOverrideCursor();
776                                                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
777                                                                 tr("SMESH_WRN_WARNING"),
778                                                                 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
779                                                                 tr("SMESH_BUT_YES"));
780                                                 }
781                                         }
782                                 }
783                                 if (myAutomaticUpdate)
784                                 {
785                                         SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
786                                         if (Mesh != NULL)
787                                         {
788 #ifdef TRACE
789                                                 Dump(Mesh);
790 #endif
791                                                 DisplayActor(Mesh);
792                                                 DisplayEdges(Mesh);
793                                                 // smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
794                                         }
795                                 }
796                         }
797                 }
798
799                 if (MorSM->FindSubObject(2, AHR))
800                 {
801                         SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
802                         for (; it->More(); it->Next())
803                         {
804                                 SALOMEDS::SObject_var Obj = it->Value();
805                                 if (Obj->ReferencedObject(aRef))
806                                 {
807                                         if (aRef->FindAttribute(anAttr, "AttributeIOR"))
808                                         {
809                                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
810                                                 if (strcmp(anIOR->Value(),
811                                                                 _orb->object_to_string(anHyp)) == 0)
812                                                 {
813                                                         smeshGUI->myStudyAPI.UnSetHypothesis(Obj);
814                                                         break;
815                                                 }
816                                         }
817                                 }
818                         }
819                 }
820                 if (MorSM->FindSubObject(3, AHR))
821                 {
822                         SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
823                         for (; it->More(); it->Next())
824                         {
825                                 SALOMEDS::SObject_var Obj = it->Value();
826                                 if (Obj->ReferencedObject(aRef))
827                                 {
828                                         if (aRef->FindAttribute(anAttr, "AttributeIOR"))
829                                         {
830                                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
831                                                 if (strcmp(anIOR->Value(),
832                                                                 _orb->object_to_string(anHyp)) == 0)
833                                                 {
834                                                         smeshGUI->myStudyAPI.UnSetAlgorithm(Obj);
835                                                         break;
836                                                 }
837                                         }
838                                 }
839                         }
840                 }
841                 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
842         }
843         QApplication::restoreOverrideCursor();
844 }
845
846 //=============================================================================
847 /*!
848  *
849  */
850 //=============================================================================
851 void SMESHGUI::AddAlgorithmOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
852         SMESH::SMESH_Hypothesis_ptr aHyp)
853 {
854         if (!aMesh->_is_nil())
855         {
856                 QApplication::setOverrideCursor(Qt::waitCursor);
857                 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
858                 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
859                 try
860                 {
861                         bool res = aMesh->AddHypothesis(aShape, aHyp);
862                         if (res)
863                         {
864                                 SALOMEDS::SObject_var SH =
865                                         myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
866                                 if (!SM->_is_nil() && !SH->_is_nil())
867                                 {
868                                         myStudyAPI.SetAlgorithms(SM, SH);
869                                         myStudyAPI.ModifiedMesh(SM, false);
870                                 }
871                         }
872                         else
873                         {
874                                 QApplication::restoreOverrideCursor();
875                                 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
876                                         tr("SMESH_WRN_WARNING"),
877                                         tr("SMESH_WRN_ALGORITHM_ALREADYEXIST"),
878                                         tr("SMESH_BUT_YES"));
879                         }
880                 }
881                 catch(const SALOME::SALOME_Exception & S_ex)
882                 {
883                         QtCatchCorbaException(S_ex);
884                 }
885         }
886         myActiveStudy->updateObjBrowser(true);
887         QApplication::restoreOverrideCursor();
888 }
889
890 //=============================================================================
891 /*!
892  *
893  */
894 //=============================================================================
895 void SMESHGUI::AddHypothesisOnSubMesh(SMESH::SMESH_subMesh_ptr aSubMesh,
896         SMESH::SMESH_Hypothesis_ptr aHyp)
897 {
898         if (!aSubMesh->_is_nil())
899         {
900                 QApplication::setOverrideCursor(Qt::waitCursor);
901                 try
902                 {
903                         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
904                         SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh(aSubMesh);
905                         GEOM::GEOM_Shape_var aShape =
906                                 myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
907                         if (!aMesh->_is_nil())
908                         {
909                                 bool res = aMesh->AddHypothesis(aShape, aHyp);
910                                 if (res)
911                                 {
912                                         SALOMEDS::SObject_var SH =
913                                                 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
914                                         if (!SsubM->_is_nil() && !SH->_is_nil())
915                                         {
916                                                 myStudyAPI.SetHypothesis(SsubM, SH);
917                                                 myStudyAPI.ModifiedMesh(SsubM, false);
918                                         }
919                                 }
920                                 else
921                                 {
922                                         QApplication::restoreOverrideCursor();
923                                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
924                                                 tr("SMESH_WRN_WARNING"),
925                                                 tr("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"),
926                                                 tr("SMESH_BUT_YES"));
927                                 }
928                         }
929                 }
930                 catch(const SALOME::SALOME_Exception & S_ex)
931                 {
932                         QtCatchCorbaException(S_ex);
933                 }
934         }
935         myActiveStudy->updateObjBrowser(true);
936         QApplication::restoreOverrideCursor();
937 }
938
939 //=============================================================================
940 /*!
941  *
942  */
943 //=============================================================================
944 void SMESHGUI::AddAlgorithmOnSubMesh(SMESH::SMESH_subMesh_ptr aSubMesh,
945         SMESH::SMESH_Hypothesis_ptr aHyp)
946 {
947         if (!aSubMesh->_is_nil())
948         {
949                 QApplication::setOverrideCursor(Qt::waitCursor);
950                 try
951                 {
952                         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
953                         SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh(aSubMesh);
954                         GEOM::GEOM_Shape_var aShape =
955                                 myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
956                         if (!aMesh->_is_nil())
957                         {
958                                 bool res = aMesh->AddHypothesis(aShape, aHyp);
959                                 if (res)
960                                 {
961                                         SALOMEDS::SObject_var SH =
962                                                 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
963                                         if (!SsubM->_is_nil() && !SH->_is_nil())
964                                         {
965                                                 myStudyAPI.SetAlgorithms(SsubM, SH);
966                                                 myStudyAPI.ModifiedMesh(SsubM, false);
967                                         }
968                                 }
969                                 else
970                                 {
971                                         QApplication::restoreOverrideCursor();
972                                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
973                                                 tr("SMESH_WRN_WARNING"),
974                                                 tr("SMESH_WRN_ALGORITHM_ALREADYEXIST"),
975                                                 tr("SMESH_BUT_YES"));
976                                 }
977                         }
978                 }
979                 catch(const SALOME::SALOME_Exception & S_ex)
980                 {
981                         QtCatchCorbaException(S_ex);
982                 }
983         }
984         myActiveStudy->updateObjBrowser(true);
985         QApplication::restoreOverrideCursor();
986 }
987
988 //=============================================================================
989 /*!
990  *
991  */
992 //=============================================================================
993 void SMESHGUI::CreateAlgorithm(QString TypeAlgo, QString NameAlgo)
994 {
995         SMESH::SMESH_Hypothesis_var Hyp;
996         try
997         {
998                 if (TypeAlgo.compare("Regular_1D") == 0)
999                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1000                 else if (TypeAlgo.compare("MEFISTO_2D") == 0)
1001                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1002                 else if (TypeAlgo.compare("Quadrangle_2D") == 0)
1003                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1004                 else if (TypeAlgo.compare("Hexa_3D") == 0)
1005                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1006                 else if (TypeAlgo.compare("NETGEN_3D") == 0)
1007                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1008
1009                 if (!Hyp->_is_nil())
1010                 {
1011                         SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms(Hyp);
1012                         myStudyAPI.SetName(SHyp, NameAlgo);
1013                 }
1014         }
1015         catch(const SALOME::SALOME_Exception & S_ex)
1016         {
1017                 QtCatchCorbaException(S_ex);
1018         }
1019         myActiveStudy->updateObjBrowser(true);
1020 }
1021
1022 //=============================================================================
1023 /*!
1024  *
1025  */
1026 //=============================================================================
1027 void SMESHGUI::CreateLocalLength(QString TypeHypothesis, QString NameHypothesis,
1028         double Length)
1029 {
1030         QApplication::setOverrideCursor(Qt::waitCursor);
1031         try
1032         {
1033                 SMESH::SMESH_Hypothesis_var Hyp =
1034                         SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1035                                 NameHypothesis));
1036                 SMESH::SMESH_LocalLength_var LL =
1037                         SMESH::SMESH_LocalLength::_narrow(Hyp);
1038                 if (!LL->_is_nil())
1039                         LL->SetLength(Length);
1040         }
1041         catch(const SALOME::SALOME_Exception & S_ex)
1042         {
1043                 QtCatchCorbaException(S_ex);
1044         }
1045         myActiveStudy->updateObjBrowser(true);
1046         QApplication::restoreOverrideCursor();
1047 }
1048
1049 //=============================================================================
1050 /*!
1051  *
1052  */
1053 //=============================================================================
1054 void SMESHGUI::CreateMaxElementArea(QString TypeHypothesis,
1055         QString NameHypothesis, double MaxArea)
1056 {
1057         QApplication::setOverrideCursor(Qt::waitCursor);
1058         try
1059         {
1060                 SMESH::SMESH_Hypothesis_var Hyp =
1061                         SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1062                                 NameHypothesis));
1063                 SMESH::SMESH_MaxElementArea_var MaxElArea =
1064                         SMESH::SMESH_MaxElementArea::_narrow(Hyp);
1065                 if (!MaxElArea->_is_nil())
1066                         MaxElArea->SetMaxElementArea(MaxArea);
1067         }
1068         catch(SALOME::SALOME_Exception & S_ex)
1069         {
1070                 QtCatchCorbaException(S_ex);
1071         }
1072
1073         myActiveStudy->updateObjBrowser(true);
1074         QApplication::restoreOverrideCursor();
1075 }
1076
1077 //=============================================================================
1078 /*!
1079  *
1080  */
1081 //=============================================================================
1082 void SMESHGUI::CreateMaxElementVolume(QString TypeHypothesis,
1083         QString NameHypothesis, double MaxVolume)
1084 {
1085         QApplication::setOverrideCursor(Qt::waitCursor);
1086         try
1087         {
1088                 SMESH::SMESH_Hypothesis_var Hyp =
1089                         SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1090                                 NameHypothesis));
1091                 SMESH::SMESH_MaxElementVolume_var MaxElVolume =
1092                         SMESH::SMESH_MaxElementVolume::_narrow(Hyp);
1093                 if (!MaxElVolume->_is_nil())
1094                         MaxElVolume->SetMaxElementVolume(MaxVolume);
1095         }
1096         catch(const SALOME::SALOME_Exception & S_ex)
1097         {
1098                 QtCatchCorbaException(S_ex);
1099         }
1100         myActiveStudy->updateObjBrowser(true);
1101         QApplication::restoreOverrideCursor();
1102 }
1103
1104 //=============================================================================
1105 /*!
1106  *
1107  */
1108 //=============================================================================
1109 void SMESHGUI::CreateNbSegments(QString TypeHypothesis, QString NameHypothesis,
1110         int nbSegments)
1111 {
1112         QApplication::setOverrideCursor(Qt::waitCursor);
1113         try
1114         {
1115                 SMESH::SMESH_Hypothesis_var Hyp =
1116                         SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1117                                 NameHypothesis));
1118                 SMESH::SMESH_NumberOfSegments_var NbS =
1119                         SMESH::SMESH_NumberOfSegments::_narrow(Hyp);
1120                 if (!NbS->_is_nil())
1121                         NbS->SetNumberOfSegments(nbSegments);
1122         }
1123         catch(const SALOME::SALOME_Exception & S_ex)
1124         {
1125                 QtCatchCorbaException(S_ex);
1126         }
1127         myActiveStudy->updateObjBrowser(true);
1128         QApplication::restoreOverrideCursor();
1129 }
1130
1131 //=============================================================================
1132 /*!
1133  *
1134  */
1135 //=============================================================================
1136 int SMESHGUI::GetNameOfSelectedIObjects(SALOME_Selection * Sel, QString & aName)
1137 {
1138         int nbSel = Sel->IObjectCount();
1139         if (nbSel == 1)
1140         {
1141                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1142                 aName = IObject->getName();
1143         }
1144         else
1145         {
1146                 aName = tr("SMESH_OBJECTS_SELECTED").arg(nbSel);
1147         }
1148         return nbSel;
1149 }
1150
1151 //=============================================================================
1152 /*!
1153  *
1154  */
1155 //=============================================================================
1156 int SMESHGUI::GetNameOfSelectedNodes(SALOME_Selection * Sel, QString & aName)
1157 {
1158         int nbNodes = 0;
1159         int nbSel = Sel->IObjectCount();
1160         if (nbSel == 1)
1161         {
1162                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1163                 if (!IObject->hasEntry())
1164                         return -1;
1165
1166                 Standard_Boolean res;
1167                 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1168                 if (!res)
1169                         return -1;
1170
1171                 TColStd_MapOfInteger MapIndex;
1172                 Sel->GetIndex(IObject, MapIndex);
1173                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1174                 aName = " ";
1175                 nbNodes = MapIndex.Extent();
1176                 for (; ite.More(); ite.Next())
1177                 {
1178                         aName =
1179                                 aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) +
1180                                 " ";
1181                 }
1182         }
1183         else
1184         {
1185                 aName = "";
1186         }
1187         return nbNodes;
1188 }
1189
1190 //=============================================================================
1191 /*!
1192  *
1193  */
1194 //=============================================================================
1195 int SMESHGUI::GetNameOfSelectedElements(SALOME_Selection * Sel, QString & aName)
1196 {
1197         int nbElements = 0;
1198         int nbSel = Sel->IObjectCount();
1199         if (nbSel == 1)
1200         {
1201                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1202                 if (!IObject->hasEntry())
1203                         return -1;
1204
1205                 Standard_Boolean res;
1206                 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1207                 if (!res)
1208                         return -1;
1209
1210                 TColStd_MapOfInteger MapIndex;
1211                 Sel->GetIndex(IObject, MapIndex);
1212                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1213                 aName = " ";
1214                 nbElements = MapIndex.Extent();
1215                 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1216                 for (; ite.More(); ite.Next())
1217                 {
1218                         int idVTK = ite.Key();
1219                         MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1220                         aName =
1221                                 aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1222                 }
1223         }
1224         else
1225         {
1226                 aName = "";
1227         }
1228         return nbElements;
1229 }
1230
1231 //=============================================================================
1232 /*!
1233  *
1234  */
1235 //=============================================================================
1236 int SMESHGUI::GetNameOfSelectedEdges(SALOME_Selection * Sel, QString & aName)
1237 {
1238         int nbElements = 0;
1239         int nbSel = Sel->IObjectCount();
1240         if (nbSel == 1)
1241         {
1242                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1243                 if (!IObject->hasEntry())
1244                         return -1;
1245
1246                 Standard_Boolean res;
1247                 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1248                 if (!res)
1249                         return -1;
1250
1251                 TColStd_MapOfInteger MapIndex;
1252                 Sel->GetIndex(IObject, MapIndex);
1253                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1254                 aName = " ";
1255                 nbElements = MapIndex.Extent();
1256                 for (; ite.More(); ite.Next())
1257                 {
1258                         aName = aName + QString("%1").arg(ite.Key()) + " ";
1259                 }
1260         }
1261         else
1262         {
1263                 aName = "";
1264         }
1265         return nbElements;
1266 }
1267
1268 //=============================================================================
1269 /*!
1270  *
1271  */
1272 //=============================================================================
1273 SMESH_Actor *SMESHGUI::FindActorByEntry(QString entry,
1274         Standard_Boolean & testResult, bool onlyInActiveView)
1275 {
1276         int nbSf = myActiveStudy->getStudyFramesCount();
1277         for (int i = 0; i < nbSf; i++)
1278         {
1279                 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
1280                 if (sf->getTypeView() == VIEW_VTK)
1281                 {
1282                         vtkRenderer *Renderer =
1283                                 ((VTKViewer_ViewFrame *) sf->getRightFrame()->getViewFrame())->
1284                                 getRenderer();
1285                         vtkActorCollection *theActors = Renderer->GetActors();
1286                         theActors->InitTraversal();
1287                         vtkActor *ac = theActors->GetNextActor();
1288                         while (!(ac == NULL))
1289                         {
1290                                 if (ac->IsA("SMESH_Actor"))
1291                                 {
1292                                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
1293                                         if (anActor->hasIO())
1294                                         {
1295                                                 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1296                                                 if (strcmp(IO->getEntry(), entry) == 0)
1297                                                 {
1298                                                         if (onlyInActiveView)
1299                                                         {
1300                                                                 if (sf == myActiveStudy->getActiveStudyFrame())
1301                                                                 {
1302                                                                         testResult = true;
1303                                                                         return anActor;
1304                                                                 }
1305                                                         }
1306                                                         else
1307                                                         {
1308                                                                 testResult = true;
1309                                                                 return anActor;
1310                                                         }
1311                                                 }
1312                                         }
1313                                 }
1314                                 ac = theActors->GetNextActor();
1315                         }
1316                 }
1317         }
1318
1319         MESSAGE(" Actor Not Found ") testResult = false;
1320         return SMESH_Actor::New();
1321 }
1322
1323 //=============================================================================
1324 /*!
1325  *
1326  */
1327 //=============================================================================
1328 SMESH_Actor *SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1329         Standard_Boolean & testResult, bool onlyInActiveView)
1330 {
1331         SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
1332         if (SM->_is_nil())
1333         {
1334                 MESSAGE(" Actor Not Found ") testResult = false;
1335                 return SMESH_Actor::New();
1336         }
1337
1338         return FindActorByEntry(SM->GetID(), testResult, onlyInActiveView);
1339 }
1340
1341 //=============================================================================
1342 /*!
1343  *
1344  */
1345 //=============================================================================
1346 SMESH::SMESH_Mesh_ptr SMESHGUI::
1347 ConvertIOinMesh(const Handle(SALOME_InteractiveObject) & IO,
1348         Standard_Boolean & testResult)
1349 {
1350         SMESH::SMESH_Mesh_var aMesh;
1351         testResult = false;
1352
1353         /* case SObject */
1354         if (IO->hasEntry())
1355         {
1356                 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1357                 SALOMEDS::GenericAttribute_var anAttr;
1358                 SALOMEDS::AttributeIOR_var anIOR;
1359                 if (!obj->_is_nil())
1360                 {
1361                         if (obj->FindAttribute(anAttr, "AttributeIOR"))
1362                         {
1363                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1364                                 aMesh =
1365                                         SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
1366                                                 Value()));
1367                                 if (!aMesh->_is_nil())
1368                                 {
1369                                         testResult = true;
1370                                         return SMESH::SMESH_Mesh::_duplicate(aMesh);
1371                                 }
1372                         }
1373                 }
1374         }
1375         return SMESH::SMESH_Mesh::_nil();
1376 }
1377
1378 //=============================================================================
1379 /*!
1380  *
1381  */
1382 //=============================================================================
1383 SMESH::SMESH_subMesh_ptr SMESHGUI::
1384 ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject) & IO,
1385         Standard_Boolean & testResult)
1386 {
1387         SMESH::SMESH_subMesh_var aSubMesh;
1388         testResult = false;
1389
1390         /* case SObject */
1391         if (IO->hasEntry())
1392         {
1393                 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1394                 SALOMEDS::GenericAttribute_var anAttr;
1395                 SALOMEDS::AttributeIOR_var anIOR;
1396                 if (!obj->_is_nil())
1397                 {
1398                         if (obj->FindAttribute(anAttr, "AttributeIOR"))
1399                         {
1400                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1401                                 aSubMesh =
1402                                         SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->
1403                                                 Value()));
1404                                 if (!aSubMesh->_is_nil())
1405                                 {
1406                                         testResult = true;
1407                                         return SMESH::SMESH_subMesh::_duplicate(aSubMesh);
1408                                 }
1409                         }
1410                 }
1411         }
1412         return SMESH::SMESH_subMesh::_nil();
1413 }
1414
1415 //=============================================================================
1416 /*!
1417  *
1418  */
1419 //=============================================================================
1420 SMESH::SMESH_Hypothesis_ptr SMESHGUI::
1421 ConvertIOinSMESHHypothesis(const Handle(SALOME_InteractiveObject) & IO,
1422         Standard_Boolean & testResult)
1423 {
1424         SMESH::SMESH_Hypothesis_var aHyp;
1425         testResult = false;
1426
1427         /* case SObject */
1428         if (IO->hasEntry())
1429         {
1430                 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1431                 SALOMEDS::GenericAttribute_var anAttr;
1432                 SALOMEDS::AttributeIOR_var anIOR;
1433                 if (!obj->_is_nil())
1434                 {
1435                         if (obj->FindAttribute(anAttr, "AttributeIOR"))
1436                         {
1437                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1438                                 aHyp =
1439                                         SMESH::SMESH_Hypothesis::_narrow(_orb->
1440                                         string_to_object(anIOR->Value()));
1441                                 if (!aHyp->_is_nil())
1442                                 {
1443                                         testResult = true;
1444                                         return SMESH::SMESH_Hypothesis::_duplicate(aHyp);
1445                                 }
1446                         }
1447                 }
1448         }
1449         return SMESH::SMESH_Hypothesis::_nil();
1450 }
1451
1452 //=============================================================================
1453 /*!
1454  *
1455  */
1456 //=============================================================================
1457 GEOM::GEOM_Shape_ptr SMESHGUI::
1458 ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject) & IO,
1459         Standard_Boolean & testResult)
1460 {
1461         GEOM::GEOM_Shape_var aShape;
1462         testResult = false;
1463
1464         /* case SObject */
1465         if (IO->hasEntry())
1466         {
1467                 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1468                 SALOMEDS::GenericAttribute_var anAttr;
1469                 SALOMEDS::AttributeIOR_var anIOR;
1470                 if (!obj->_is_nil())
1471                 {
1472                         if (obj->FindAttribute(anAttr, "AttributeIOR"))
1473                         {
1474                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1475                                 aShape = myComponentGeom->GetIORFromString(anIOR->Value());
1476                                 if (!aShape->_is_nil())
1477                                 {
1478                                         testResult = true;
1479                                         return GEOM::GEOM_Shape::_duplicate(aShape);
1480                                 }
1481                         }
1482                 }
1483         }
1484         return GEOM::GEOM_Shape::_nil();
1485 }
1486
1487 //=============================================================================
1488 /*!
1489  *
1490  */
1491 //=============================================================================
1492 void SMESHGUI::SetViewMode(int commandId)
1493 {
1494         SALOME_Selection *Sel =
1495                 SALOME_Selection::Selection(myActiveStudy->getSelection());
1496         int nbSel = Sel->IObjectCount();
1497         if (nbSel >= 1)
1498         {
1499                 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1500                 for (; It.More(); It.Next())
1501                 {
1502                         Handle(SALOME_InteractiveObject) IObject = It.Value();
1503                         if (IObject->hasEntry())
1504                         {
1505                                 Standard_Boolean res;
1506                                 SMESH_Actor *ac =
1507                                         FindActorByEntry(IObject->getEntry(), res, true);
1508                                 if (res)
1509                                 {
1510                                         switch (commandId)
1511                                         {
1512                                         case 211:
1513                                         {
1514                                                 ChangeRepresentation(ac, 0);
1515                                                 break;
1516                                         }
1517                                         case 212:
1518                                         {
1519                                                 ChangeRepresentation(ac, 1);
1520                                                 break;
1521                                         }
1522                                         case 213:
1523                                         {
1524                                                 ChangeRepresentation(ac, 2);
1525                                                 break;
1526                                         }
1527                                         case 1132:
1528                                         {
1529                                                 ChangeRepresentation(ac, 3);
1530                                                 break;
1531                                         }
1532                                         }
1533                                 }
1534                         }
1535                 }
1536                 if (commandId == 1133)
1537                 {
1538                         ChangeRepresentation(SMESH_Actor::New(), 4);
1539                 }
1540         }
1541 }
1542
1543 //=============================================================================
1544 /*!
1545  *
1546  */
1547 //=============================================================================
1548 void SMESHGUI::ChangeRepresentation(SMESH_Actor * ac, int type)
1549 {
1550         if (ac->DataSource == NULL && type != 4)
1551                 return;
1552
1553         if (type != 4)
1554         {
1555                 if (ac->getMapper() == NULL)
1556                 {
1557                         return;
1558                 }
1559         }
1560         switch (type)
1561         {
1562         case 0:
1563         {
1564                 QApplication::setOverrideCursor(Qt::waitCursor);
1565                 if (ac->getDisplayMode() == 2)
1566                 {
1567                         bool isColored = ac->getMapper()->GetScalarVisibility();        //SAL3899
1568                         vtkDataSetMapper *meshMapper =
1569                                 (vtkDataSetMapper *) (ac->getMapper());
1570                         meshMapper->SetInput(ac->DataSource);
1571                         meshMapper->SetScalarVisibility(isColored);     //SAL3899
1572                 }
1573                 ac->setDisplayMode(0);
1574                 ac->GetProperty()->SetRepresentationToWireframe();
1575                 //    ac->SetActorProperty( ac->GetProperty() );
1576                 QApplication::restoreOverrideCursor();
1577                 break;
1578         }
1579         case 1:
1580         {
1581                 QApplication::setOverrideCursor(Qt::waitCursor);
1582                 if (ac->getDisplayMode() == 2)
1583                 {
1584                         bool isColored = ac->getMapper()->GetScalarVisibility();        //SAL3899
1585                         vtkDataSetMapper *meshMapper =
1586                                 (vtkDataSetMapper *) (ac->getMapper());
1587                         meshMapper->SetInput(ac->DataSource);
1588                         meshMapper->SetScalarVisibility(isColored);     //SAL3899
1589                 }
1590                 ac->setDisplayMode(1);
1591                 ac->GetProperty()->SetRepresentationToSurface();
1592                 QApplication::restoreOverrideCursor();
1593                 //    ac->SetActorProperty( ac->GetProperty() );
1594                 break;
1595         }
1596         case 2:
1597         {
1598                 //    if (!(ac->getDisplayMode()==2)) {
1599                 //    ChangeRepresentation(ac, 1);
1600                 QApplication::setOverrideCursor(Qt::waitCursor);
1601                 ac->setDisplayMode(2);
1602                 bool isColored = ac->getMapper()->GetScalarVisibility();        //SAL3899
1603                 vtkDataSetMapper *meshMapper = (vtkDataSetMapper *) (ac->getMapper());
1604                 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1605                 shrink->SetInput(ac->DataSource);
1606                 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1607
1608                 meshMapper->SetInput(shrink->GetOutput());
1609                 meshMapper->SetScalarVisibility(isColored);     //SAL3899
1610                 ac->SetMapper(meshMapper);
1611                 QApplication::restoreOverrideCursor();
1612                 //    }
1613                 break;
1614         }
1615         case 3:
1616         {
1617                 float color[3];
1618                 float edgecolor[3];
1619                 float backfacecolor[3];
1620                 float nodecolor[3];
1621                 ac->GetColor(color[0], color[1], color[2]);
1622 //       QColor c(color[0]*255,color[1]*255,color[2]*255);
1623                 int c0 = int (color[0] * 255);
1624                 int c1 = int (color[1] * 255);
1625                 int c2 = int (color[2] * 255);
1626                 QColor c(c0, c1, c2);
1627                 ac->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
1628 //       QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1629                 c0 = int (edgecolor[0] * 255);
1630                 c1 = int (edgecolor[1] * 255);
1631                 c2 = int (edgecolor[2] * 255);
1632                 QColor e(c0, c1, c2);
1633                 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1634 //       QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1635                 c0 = int (backfacecolor[0] * 255);
1636                 c1 = int (backfacecolor[1] * 255);
1637                 c2 = int (backfacecolor[2] * 255);
1638                 QColor b(c0, c1, c2);
1639                 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1640 //       QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1641                 c0 = int (nodecolor[0] * 255);
1642                 c1 = int (nodecolor[1] * 255);
1643                 c2 = int (nodecolor[2] * 255);
1644                 QColor n(c0, c1, c2);
1645
1646                 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1647                 if (Edgewidth == 0)
1648                         Edgewidth = 1;
1649                 int intValue = ac->GetNodeSize();
1650                 float Shrink = ac->GetShrinkFactor();
1651
1652                 SMESHGUI_Preferences_ColorDlg *aDlg =
1653                         new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(),
1654                         "");
1655                 aDlg->SetColor(1, c);
1656                 aDlg->SetColor(2, e);
1657                 aDlg->SetColor(3, n);
1658                 aDlg->SetColor(4, b);
1659                 aDlg->SetIntValue(1, Edgewidth);
1660                 aDlg->SetIntValue(2, intValue);
1661                 aDlg->SetIntValue(3, int (Shrink * 100.));
1662
1663                 if (aDlg->exec())
1664                 {
1665                         QApplication::setOverrideCursor(Qt::waitCursor);
1666                         QColor color = aDlg->GetColor(1);
1667                         QColor edgecolor = aDlg->GetColor(2);
1668                         QColor nodecolor = aDlg->GetColor(3);
1669                         QColor backfacecolor = aDlg->GetColor(4);
1670                         /* actor color and backface color */
1671                         ac->GetProperty()->SetColor(float (color.red()) / 255.,
1672                                 float (color.green()) / 255., float (color.blue()) / 255.);
1673                         ac->SetColor(float (color.red()) / 255.,
1674                                 float (color.green()) / 255., float (color.blue()) / 255.);
1675                         ac->GetBackfaceProperty()->SetColor(float (backfacecolor.red()) /
1676                                 255., float (backfacecolor.green()) / 255.,
1677                                 float (backfacecolor.blue()) / 255.);
1678
1679                         /* edge color */
1680                         ac->EdgeDevice->GetProperty()->SetColor(float (edgecolor.red()) /
1681                                 255., float (edgecolor.green()) / 255.,
1682                                 float (edgecolor.blue()) / 255.);
1683                         ac->EdgeShrinkDevice->GetProperty()->SetColor(float (edgecolor.
1684                                         red()) / 255., float (edgecolor.green()) / 255.,
1685                                 float (edgecolor.blue()) / 255.);
1686                         ac->SetEdgeColor(float (edgecolor.red()) / 255.,
1687                                 float (edgecolor.green()) / 255.,
1688                                 float (edgecolor.blue()) / 255.);
1689
1690                         /* Shrink factor and size edges */
1691                         ac->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
1692                         ac->EdgeDevice->GetProperty()->SetLineWidth(aDlg->GetIntValue(1));
1693                         ac->EdgeShrinkDevice->GetProperty()->SetLineWidth(aDlg->
1694                                 GetIntValue(1));
1695
1696                         /* Nodes color and size */
1697                         ac->SetNodeColor(float (nodecolor.red()) / 255.,
1698                                 float (nodecolor.green()) / 255.,
1699                                 float (nodecolor.blue()) / 255.);
1700                         ac->SetNodeSize(aDlg->GetIntValue(2));
1701
1702                         if (ac->getDisplayMode() == 2)
1703                         {
1704                                 bool isColored = ac->getMapper()->GetScalarVisibility();        //SAL3899
1705                                 vtkDataSetMapper *meshMapper =
1706                                         (vtkDataSetMapper *) (ac->getMapper());
1707                                 meshMapper->SetInput(ac->DataSource);
1708                                 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1709                                 shrink->SetInput(meshMapper->GetInput());
1710                                 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1711
1712                                 meshMapper->SetInput(shrink->GetOutput());
1713                                 meshMapper->SetScalarVisibility(isColored);     //SAL3899
1714                                 ac->SetMapper(meshMapper);
1715                         }
1716                 }
1717                 delete aDlg;
1718                 QApplication::restoreOverrideCursor();
1719                 break;
1720         }
1721         case 4:
1722         {
1723                 EmitSignalDeactivateDialog();
1724                 SALOME_Selection *Sel =
1725                         SALOME_Selection::Selection(myActiveStudy->getSelection());
1726                 SMESHGUI_TransparencyDlg *aDlg =
1727                         new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(), "",
1728                         Sel);
1729                 break;
1730         }
1731         case 5:
1732         {
1733                 QApplication::setOverrideCursor(Qt::waitCursor);
1734                 ac->GetProperty()->SetRepresentationToPoints();
1735                 QApplication::restoreOverrideCursor();
1736                 break;
1737         }
1738         }
1739
1740         QApplication::setOverrideCursor(Qt::waitCursor);
1741         if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
1742         {                                                       //VTK
1743                 vtkRenderer *theRenderer =
1744                         ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1745                         getRightFrame()->getViewFrame())->getRenderer();
1746                 theRenderer->Render();
1747         }
1748         QApplication::restoreOverrideCursor();
1749 }
1750
1751 //=============================================================================
1752 /*!
1753  *
1754  */
1755 //=============================================================================
1756 void SMESHGUI::UpdateView()
1757 {
1758         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1759                 return;
1760
1761         vtkRenderer *theRenderer =
1762                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1763                 getRightFrame()->getViewFrame())->getRenderer();
1764         theRenderer->Render();
1765 }
1766
1767 //=============================================================================
1768 /*!
1769  *
1770  */
1771 //=============================================================================
1772 void SMESHGUI::DisplayActor(SMESH_Actor * ac, bool visibility)
1773 {
1774         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1775                 return;
1776
1777         MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1778
1779         vtkRenderer *theRenderer =
1780                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1781                 getRightFrame()->getViewFrame())->getRenderer();
1782         vtkActorCollection *theActors = theRenderer->GetActors();
1783         theActors->InitTraversal();
1784         if (theActors->IsItemPresent(ac) == 0)
1785         {
1786                 vtkProperty *prop = vtkProperty::New();
1787                 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").
1788                         toFloat() / 255.,
1789                         QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat() /
1790                         255.,
1791                         QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat() /
1792                         255.);
1793
1794                 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
1795                         toInt());
1796                 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
1797                         toInt());
1798                 ac->SetProperty(prop);
1799                 ac->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").
1800                         toFloat() / 255.,
1801                         QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat() /
1802                         255.,
1803                         QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat() /
1804                         255.);
1805
1806                 //    prop->BackfaceCullingOn();
1807                 vtkProperty *backprop = vtkProperty::New();
1808                 backprop->SetColor(QAD_CONFIG->
1809                         getSetting("SMESH:SettingsBackFaceColorRed").toFloat() / 255.,
1810                         QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").
1811                         toFloat() / 255.,
1812                         QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").
1813                         toFloat() / 255.);
1814                 ac->SetBackfaceProperty(backprop);
1815
1816                 int intValue =
1817                         QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1818                 if (intValue == 0)
1819                         intValue = 80;
1820                 ac->SetShrinkFactor(intValue / 100.);
1821
1822                 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1823                 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1824
1825                 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1826                 if (DisplayMode.compare("Wireframe") == 0)
1827                 {
1828                         ac->setDisplayMode(0);
1829                         ChangeRepresentation(ac, 0);
1830                 }
1831                 else if (DisplayMode.compare("Shading") == 0)
1832                 {
1833                         ac->setDisplayMode(1);
1834                         ChangeRepresentation(ac, 1);
1835                 }
1836                 else if (DisplayMode.compare("Shrink") == 0)
1837                 {
1838                         ac->setDisplayMode(2);
1839                         ChangeRepresentation(ac, 2);
1840                 }
1841                 theRenderer->AddActor(ac);
1842         }
1843         else
1844         {
1845                 if (ac->GetMapper())
1846                         ac->GetMapper()->Update();
1847         }
1848
1849 //  if ( visibility )
1850         ac->SetVisibility(visibility);
1851 //    ac->VisibilityOn();
1852 //  else
1853 //    ac->VisibilityOff();
1854
1855         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1856         renWin->Render();
1857 }
1858
1859 //=============================================================================
1860 /*!
1861  *
1862  */
1863 //=============================================================================
1864 void SMESHGUI::EraseActor(SMESH_Actor * ac)
1865 {
1866         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1867                 return;
1868
1869         vtkRenderer *theRenderer =
1870                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1871                 getRightFrame()->getViewFrame())->getRenderer();
1872
1873         //NRI- : 02/12/2002 : Fixed bugId 882
1874         //  ac->EdgeDevice->VisibilityOff();
1875         //  ac->EdgeShrinkDevice->VisibilityOff();
1876         //  ac->VisibilityOff();
1877         ac->SetVisibility(false);
1878
1879         theRenderer->Render();
1880 }
1881
1882 //=============================================================================
1883 /*!
1884  *
1885  */
1886 //=============================================================================
1887 bool SMESHGUI::AddActorInSelection(SMESH_Actor * ac)
1888 {
1889         SALOME_Selection *Sel =
1890                 SALOME_Selection::Selection(myActiveStudy->getSelection());
1891         Sel->ClearIObjects();
1892         if (ac->hasIO())
1893                 return Sel->AddIObject(ac->getIO());
1894         else
1895                 return -1;
1896 }
1897
1898 //=============================================================================
1899 /*!
1900  *
1901  */
1902 //=============================================================================
1903 QString SMESHGUI::CheckHomogeneousSelection()
1904 {
1905         SALOME_Selection *Sel =
1906                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
1907         /* copy the list */
1908         SALOME_ListIO List;
1909         SALOME_ListIteratorOfListIO Itinit(Sel->StoredIObjects());
1910         for (; Itinit.More(); Itinit.Next())
1911         {
1912                 List.Append(Itinit.Value());
1913         }
1914
1915         QString RefType = CheckTypeObject(Sel->firstIObject());
1916         SALOME_ListIteratorOfListIO It(List);
1917         for (; It.More(); It.Next())
1918         {
1919                 Handle(SALOME_InteractiveObject) IObject = It.Value();
1920                 QString Type = CheckTypeObject(IObject);
1921                 if (Type.compare(RefType) != 0)
1922                         return "Heterogeneous Selection";
1923         }
1924
1925         Sel->ClearIObjects();
1926         SALOME_ListIteratorOfListIO It1(List);
1927         for (; It1.More(); It1.Next())
1928         {
1929                 int res = Sel->AddIObject(It1.Value());
1930                 if (res == -1)
1931                         myActiveStudy->highlight(It1.Value(), false);
1932                 if (res == 0)
1933                         myActiveStudy->highlight(It1.Value(), true);
1934         }
1935         return RefType;
1936 }
1937
1938 //=============================================================================
1939 /*!
1940  *
1941  */
1942 //=============================================================================
1943 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject) & IO)
1944 {
1945         SALOMEDS::SObject_var sobj =
1946                 smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->
1947                 getEntry());
1948         if (!sobj->_is_nil())
1949         {
1950                 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1951                 if (strcmp(scomp->GetID(), IO->getEntry()) == 0)
1952                 {                                               // component is selected
1953                         return "Component";
1954                 }
1955         }
1956
1957         SALOME_Selection *Sel =
1958                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
1959         Sel->ClearIObjects();
1960
1961         Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter(HYPOTHESIS);
1962         Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter(ALGORITHM);
1963         Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter(MESH);
1964         Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter(SUBMESH);
1965         Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter =
1966                 new SMESH_TypeFilter(MESHorSUBMESH);
1967         Handle(SMESH_TypeFilter) aSubMeshVextexFilter =
1968                 new SMESH_TypeFilter(SUBMESH_VERTEX);
1969         Handle(SMESH_TypeFilter) aSubMeshEdgeFilter =
1970                 new SMESH_TypeFilter(SUBMESH_EDGE);
1971         Handle(SMESH_TypeFilter) aSubMeshFaceFilter =
1972                 new SMESH_TypeFilter(SUBMESH_FACE);
1973         Handle(SMESH_TypeFilter) aSubMeshSolidFilter =
1974                 new SMESH_TypeFilter(SUBMESH_SOLID);
1975         Handle(SMESH_TypeFilter) aSubMeshCompoundFilter =
1976                 new SMESH_TypeFilter(SUBMESH_COMPOUND);
1977
1978         Sel->AddFilter(aHypFilter);
1979         if (Sel->AddIObject(IO) != -1)
1980         {
1981                 Sel->ClearFilters();
1982                 return "Hypothesis";
1983         }
1984
1985         Sel->ClearFilters();
1986         Sel->AddFilter(anAlgoFilter);
1987         if (Sel->AddIObject(IO) != -1)
1988         {
1989                 Sel->ClearFilters();
1990                 return "Algorithm";
1991         }
1992
1993         Sel->ClearFilters();
1994         Sel->AddFilter(aMeshFilter);
1995         if (Sel->AddIObject(IO) != -1)
1996         {
1997                 Sel->ClearFilters();
1998                 return "Mesh";
1999         }
2000
2001         Sel->ClearFilters();
2002         Sel->AddFilter(aSubMeshFilter);
2003         if (Sel->AddIObject(IO) != -1)
2004         {
2005                 Sel->ClearFilters();
2006                 return "SubMesh";
2007         }
2008
2009         Sel->ClearFilters();
2010         Sel->AddFilter(aSubMeshVextexFilter);
2011         if (Sel->AddIObject(IO) != -1)
2012         {
2013                 Sel->ClearFilters();
2014                 return "SubMeshVertex";
2015         }
2016
2017         Sel->ClearFilters();
2018         Sel->AddFilter(aSubMeshEdgeFilter);
2019         if (Sel->AddIObject(IO) != -1)
2020         {
2021                 Sel->ClearFilters();
2022                 return "SubMeshEdge";
2023         }
2024
2025         Sel->ClearFilters();
2026         Sel->AddFilter(aSubMeshFaceFilter);
2027         if (Sel->AddIObject(IO) != -1)
2028         {
2029                 Sel->ClearFilters();
2030                 return "SubMeshFace";
2031         }
2032
2033         Sel->ClearFilters();
2034         Sel->AddFilter(aSubMeshSolidFilter);
2035         if (Sel->AddIObject(IO) != -1)
2036         {
2037                 Sel->ClearFilters();
2038                 return "SubMeshSolid";
2039         }
2040
2041         Sel->ClearFilters();
2042         Sel->AddFilter(aSubMeshCompoundFilter);
2043         if (Sel->AddIObject(IO) != -1)
2044         {
2045                 Sel->ClearFilters();
2046                 return "SubMeshCompound";
2047         }
2048
2049         Sel->ClearFilters();
2050         Sel->AddIObject(IO);
2051         return "NoType";
2052 }
2053
2054 //=============================================================================
2055 /*!
2056  *
2057  */
2058 //=============================================================================
2059 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
2060 {
2061         /* Create or retrieve an object SMESHGUI */
2062         SMESHGUI::GetOrCreateSMESHGUI(parent);
2063
2064         // NRI : Temporary added
2065         if (smeshGUI->myStudy->GetProperties()->IsLocked())
2066         {
2067                 return false;
2068         }
2069         //NRI
2070
2071         //  QAD_Viewer3d* v3d;
2072         OCCViewer_Viewer3d *v3d;
2073
2074         Handle(AIS_InteractiveContext) ic;
2075         vtkRenderer *Renderer;
2076         vtkRenderWindow *RenWin;
2077
2078         if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2079                 VIEW_OCC)
2080         {
2081                 v3d =
2082                         ((OCCViewer_ViewFrame *) smeshGUI->myActiveStudy->
2083                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2084                         getViewer();
2085                 ic = v3d->getAISContext();
2086         }
2087         else if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2088                 VIEW_VTK)
2089         {
2090                 Renderer =
2091                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2092                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2093                         getRenderer();
2094                 RenWin = Renderer->GetRenderWindow();
2095         }
2096
2097         switch (theCommandID)
2098         {
2099         case 33:                                        // DELETE
2100                 smeshGUI->OnEditDelete();
2101                 break;
2102
2103         case 113:                                       // IMPORT
2104         case 112:
2105         case 111:
2106         {
2107                 Import_Document(parent, theCommandID);  //NBU
2108                 //Import_Mesh(parent,theCommandID);
2109                 break;
2110         }
2111
2112         case 122:                                       // EXPORT MED
2113         case 121:
2114         case 123:
2115         {
2116                 Export_Mesh(parent, theCommandID);
2117                 break;
2118         }
2119
2120         case 200:                                       // SCALAR BAR
2121         {
2122                 smeshGUI->DisplayScalarBar(false);
2123                 break;
2124         }
2125         case 201:
2126         {
2127                 SMESHGUI_EditScalarBarDlg *aDlg =
2128                         new SMESHGUI_EditScalarBarDlg(parent, "", false);
2129                 aDlg->show();
2130                 break;
2131         }
2132         case 202:
2133         {
2134                 smeshGUI->DisplayScalarBar(true);
2135                 break;
2136         }
2137
2138         case 1133:                                      // DISPLAY MODE : WireFrame, Surface, Shrink
2139         case 1132:
2140         case 213:
2141         case 212:
2142         case 211:
2143         {
2144                 smeshGUI->SetViewMode(theCommandID);
2145                 break;
2146         }
2147
2148         case 214:                                       // UPDATE
2149         {
2150                 smeshGUI->Update();
2151                 break;
2152         }
2153
2154         case 300:                                       // ERASE
2155         {
2156                 SALOME_Selection *Sel =
2157                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2158                         getSelection());
2159                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2160                         VIEW_VTK)
2161                 {
2162                         // VTK
2163                         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2164                         for (; It.More(); It.Next())
2165                         {
2166                                 Handle(SALOME_InteractiveObject) IOS = It.Value();
2167                                 if (IOS->hasEntry())
2168                                 {
2169                                         Standard_Boolean res;
2170                                         SMESH_Actor *ac =
2171                                                 smeshGUI->FindActorByEntry(IOS->getEntry(), res, true);
2172                                         if (res)
2173                                                 smeshGUI->EraseActor(ac);
2174                                 }
2175                         }
2176                 }
2177                 Sel->ClearIObjects();
2178                 smeshGUI->myActiveStudy->updateObjBrowser(true);
2179         }
2180
2181         case 301:                                       // DISPLAY
2182         {
2183                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2184                         VIEW_VTK)
2185                 {
2186                         // VTK
2187                         QApplication::setOverrideCursor(Qt::waitCursor);
2188                         SALOMEDS::SObject_var fatherSF =
2189                                 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->
2190                                 getActiveStudyFrame()->entry());
2191
2192                         SALOME_Selection *Sel =
2193                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2194                                 getSelection());
2195                         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2196
2197                         for (; It.More(); It.Next())
2198                         {
2199                                 Handle(SALOME_InteractiveObject) IObject = It.Value();
2200                                 if (IObject->hasEntry())
2201                                 {
2202                                         Standard_Boolean res;
2203                                         SMESH_Actor *ac =
2204                                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res,
2205                                                 false);
2206                                         if (res)
2207                                         {
2208                                                 smeshGUI->DisplayActor(ac, true);
2209                                                 smeshGUI->DisplayEdges(ac);
2210                                                 smeshGUI->ChangeRepresentation(ac,
2211                                                         ac->getDisplayMode());
2212                                         }
2213                                 }
2214                         }
2215                         QApplication::restoreOverrideCursor();
2216                 }
2217                 break;
2218         }
2219
2220         case 302:                                       // DISPLAY ONLY
2221         {
2222                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2223                         VIEW_VTK)
2224                 {
2225                         QApplication::setOverrideCursor(Qt::waitCursor);
2226                         vtkActorCollection *theActors = Renderer->GetActors();
2227                         theActors->InitTraversal();
2228                         vtkActor *ac = theActors->GetNextActor();
2229                         while (!(ac == NULL))
2230                         {
2231                                 if (ac->IsA("SMESH_Actor"))
2232                                 {
2233                                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
2234                                         if (!anActor->isHighlighted())
2235                                         {
2236                                                 //anActor->VisibilityOff();
2237                                                 //NRI- : 02/12/2002 : Fixed bugId 882
2238                                                 //      anActor->EdgeDevice->VisibilityOff();
2239                                                 //      anActor->EdgeShrinkDevice->VisibilityOff();
2240                                                 anActor->SetVisibility(false);
2241                                         }
2242                                 }
2243                                 ac = theActors->GetNextActor();
2244                         }
2245
2246                         // Display selection
2247                         SALOMEDS::SObject_var fatherSF =
2248                                 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->
2249                                 getActiveStudyFrame()->entry());
2250
2251                         SALOME_Selection *Sel =
2252                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2253                                 getSelection());
2254                         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2255
2256                         for (; It.More(); It.Next())
2257                         {
2258                                 Handle(SALOME_InteractiveObject) IObject = It.Value();
2259                                 SALOMEDS::SObject_var obj =
2260                                         smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2261
2262                                 VTKViewer_RenderWindowInteractor *myRenderInter =
2263                                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2264                                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2265                                         getRWInteractor();
2266                                 //      vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
2267
2268                                 if (myRenderInter->isInViewer(IObject))
2269                                 {
2270                                         if (IObject->hasEntry())
2271                                         {
2272                                                 Standard_Boolean res;
2273                                                 SMESH_Actor *ac =
2274                                                         smeshGUI->FindActorByEntry(IObject->getEntry(), res,
2275                                                         true);
2276                                                 if (res)
2277                                                 {
2278                                                         smeshGUI->DisplayActor(ac, true);
2279                                                         smeshGUI->DisplayEdges(ac);
2280                                                         smeshGUI->ChangeRepresentation(ac,
2281                                                                 ac->getDisplayMode());
2282                                                 }
2283                                         }
2284                                 }
2285                         }
2286                         smeshGUI->myActiveStudy->updateObjBrowser(true);
2287                         QApplication::restoreOverrideCursor();
2288                 }
2289                 break;
2290         }
2291
2292         case 400:                                       // NODES
2293         {
2294                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2295                         VIEW_VTK)
2296                 {                                               //VTK
2297                         smeshGUI->EmitSignalDeactivateDialog();
2298                         SALOME_Selection *Sel =
2299                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2300                                 getSelection());
2301                         Sel->ClearIObjects();
2302                         smeshGUI->myDesktop->SetSelectionMode(1, true);
2303                         parent->menuBar()->setItemChecked(9010, false);
2304                         parent->menuBar()->setItemChecked(9011, false);
2305                         smeshGUI->ViewNodes();
2306                         SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg(parent, "", Sel);
2307                 }
2308                 else
2309                 {
2310                         QApplication::restoreOverrideCursor();
2311                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2312                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2313                                 tr("SMESH_BUT_YES"));
2314                 }
2315                 break;
2316         }
2317
2318         case 405:                                       // MOVE NODE
2319         {
2320                 smeshGUI->myDesktop->SetSelectionMode(1, true);
2321                 SALOME_Selection *Sel =
2322                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2323                         getSelection());
2324                 SMESHGUI_MoveNodesDlg *aDlg =
2325                         new SMESHGUI_MoveNodesDlg(parent, "", Sel);
2326                 break;
2327         }
2328
2329         case 701:                                       // COMPUTE MESH 
2330         {
2331                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2332                         VIEW_VTK)
2333                 {                                               //VTK
2334                         SALOME_Selection *Sel =
2335                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2336                                 getSelection());
2337                         int nbSel = Sel->IObjectCount();
2338                         if (nbSel != 1)
2339                         {
2340                                 QApplication::restoreOverrideCursor();
2341                                 break;
2342                         }
2343
2344                         SMESH::SMESH_Mesh_var aM;
2345                         SMESH::SMESH_subMesh_var aSubM;
2346                         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2347                         if (IObject->hasEntry())
2348                         {
2349                                 SALOMEDS::SObject_var aMorSM =
2350                                         smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2351                                 SALOMEDS::GenericAttribute_var anAttr;
2352                                 SALOMEDS::AttributeIOR_var anIOR;
2353                                 if (!aMorSM->_is_nil())
2354                                 {
2355                                         if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
2356                                         {
2357                                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2358                                                 MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : IOR = "
2359                                                         << anIOR->Value())CORBA::Object_var cobj;
2360                                                 try
2361                                                 {
2362                                                         cobj = _orb->string_to_object(anIOR->Value());
2363                                                         if (CORBA::is_nil(cobj))
2364                                                         {
2365                                                         MESSAGE
2366                                                                         ("SMESHGUI::OnGUIEvent - Compute mesh : nil object")}
2367                                                 }
2368                                                 catch(CORBA::COMM_FAILURE & ex)
2369                                                 {
2370                                                 MESSAGE
2371                                                                 ("SMESHGUI::OnGUIEvent - Compute mesh : exception (1)")}
2372                                                 aM = SMESH::SMESH_Mesh::_narrow(cobj);
2373                                                 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
2374                                                 aSubM =
2375                                                         SMESH::SMESH_subMesh::_narrow(_orb->
2376                                                         string_to_object(anIOR->Value()));
2377                                                 if (!aM->_is_nil())
2378                                                 {
2379                                                         GEOM::GEOM_Shape_var refShape =
2380                                                                 smeshGUI->myStudyAPI.
2381                                                                 GetShapeOnMeshOrSubMesh(aMorSM);
2382                                                         if (!refShape->_is_nil())
2383                                                         {
2384                                                                 bool compute =
2385                                                                         smeshGUI->myComponentMesh->
2386                                                                         IsReadyToCompute(aM, refShape);
2387                                                                 if (!compute)
2388                                                                 {
2389                                                                         QApplication::restoreOverrideCursor();
2390                                                                         QAD_MessageBox::warn1(QAD_Application::
2391                                                                                 getDesktop(), tr("SMESH_WRN_WARNING"),
2392                                                                                 tr("SMESH_WRN_MISSING_PARAMETERS"),
2393                                                                                 tr("SMESH_BUT_YES"));
2394                                                                         break;
2395                                                                 }
2396                                                                 try
2397                                                                 {
2398                                                                         smeshGUI->myComponentMesh->Compute(aM,
2399                                                                                 refShape);
2400                                                                         smeshGUI->myStudyAPI.ModifiedMesh(aMorSM,
2401                                                                                 true);
2402                                                                         // TO Do : change icon of all submeshes
2403                                                                 }
2404                                                                 catch(const SALOME::SALOME_Exception & S_ex)
2405                                                                 {
2406                                                                         QtCatchCorbaException(S_ex);
2407                                                                 }
2408                                                         }
2409                                                 }
2410                                                 else if (!aSubM->_is_nil())
2411                                                 {
2412                                                         aM = aSubM->GetFather();
2413                                                         GEOM::GEOM_Shape_var refShape =
2414                                                                 smeshGUI->myStudyAPI.
2415                                                                 GetShapeOnMeshOrSubMesh(aMorSM);
2416                                                         if (!refShape->_is_nil())
2417                                                         {
2418                                                                 bool compute =
2419                                                                         smeshGUI->myComponentMesh->
2420                                                                         IsReadyToCompute(aM, refShape);
2421                                                                 if (!compute)
2422                                                                 {
2423                                                                         QApplication::restoreOverrideCursor();
2424                                                                         QAD_MessageBox::warn1(QAD_Application::
2425                                                                                 getDesktop(), tr("SMESH_WRN_WARNING"),
2426                                                                                 tr("SMESH_WRN_MISSING_PARAMETERS"),
2427                                                                                 tr("SMESH_BUT_YES"));
2428                                                                         break;
2429                                                                 }
2430                                                                 try
2431                                                                 {
2432                                                                         smeshGUI->myComponentMesh->Compute(aM,
2433                                                                                 refShape);
2434                                                                         smeshGUI->myStudyAPI.ModifiedMesh(aMorSM,
2435                                                                                 true);
2436                                                                         // TO Do : change icon of all submeshes
2437                                                                 }
2438                                                                 catch(const SALOME::SALOME_Exception & S_ex)
2439                                                                 {
2440                                                                         QtCatchCorbaException(S_ex);
2441                                                                 }
2442                                                         }
2443                                                 }
2444                                         }
2445                                 }
2446                         }
2447
2448                         // Check whether the actor for the mesh exists at least in one view
2449                         Standard_Boolean res;
2450                         SMESH_Actor *ac =
2451                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2452                         if (!res)
2453                                 smeshGUI->InitActor(aM);
2454                         else
2455                         {
2456                                 // Check whether the actor belongs to the active view
2457                                 VTKViewer_RenderWindowInteractor *rwInter =
2458                                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2459                                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2460                                         getRWInteractor();
2461
2462                                 // The actor belongs to inactive view -> create a copy and add it in the active view
2463                                 if (!rwInter->isInViewer(IObject))
2464                                 {
2465                                         SMESH_Actor *acCopy = SMESH_Actor::New();
2466                                         acCopy->ShallowCopy(ac);
2467
2468                                         smeshGUI->DisplayActor(acCopy, false);
2469                                 }
2470                         }
2471
2472                         if (smeshGUI->myAutomaticUpdate)
2473                         {
2474                                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aM);
2475                                 if (Mesh != NULL)
2476                                 {
2477 #ifdef TRACE
2478                                         Dump(Mesh);
2479 #endif
2480                                         smeshGUI->DisplayActor(Mesh, true);
2481                                         smeshGUI->DisplayEdges(Mesh, true);
2482                                         smeshGUI->ChangeRepresentation(Mesh,
2483                                                 Mesh->getDisplayMode());
2484                                 }
2485                         }
2486                 }
2487                 else
2488                 {
2489                         QApplication::restoreOverrideCursor();
2490                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2491                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2492                                 tr("SMESH_BUT_YES"));
2493                 }
2494                 QApplication::restoreOverrideCursor();
2495                 break;
2496         }
2497
2498         case 702:                                       // ADD SUB MESH 
2499         {
2500                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2501                         VIEW_VTK)
2502                 {                                               //VTK
2503                         smeshGUI->EmitSignalDeactivateDialog();
2504                         SALOME_Selection *Sel =
2505                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2506                                 getSelection());
2507                         SMESHGUI_AddSubMeshDlg *aDlg =
2508                                 new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
2509                 }
2510                 else
2511                 {
2512                         QApplication::restoreOverrideCursor();
2513                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2514                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2515                                 tr("SMESH_BUT_YES"));
2516                 }
2517                 break;
2518         }
2519
2520         case 703:                                       // INIT MESH 
2521         {
2522                 smeshGUI->EmitSignalDeactivateDialog();
2523                 SALOME_Selection *Sel =
2524                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2525                         getSelection());
2526                 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg(parent, "", Sel);
2527                 break;
2528         }
2529
2530         case 704:                                       // EDIT Hypothesis 
2531         {
2532                 smeshGUI->EmitSignalDeactivateDialog();
2533                 SALOME_Selection *Sel =
2534                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2535                         getSelection());
2536                 SMESHGUI_EditHypothesesDlg *aDlg =
2537                         new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2538                 break;
2539         }
2540
2541         case 705:                                       //  EDIT Global Hypothesis
2542         {
2543                 smeshGUI->EmitSignalDeactivateDialog();
2544                 SALOME_Selection *Sel =
2545                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2546                         getSelection());
2547                 SMESHGUI_EditHypothesesDlg *aDlg =
2548                         new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2549                 break;
2550         }
2551
2552         case 706:                                       //  EDIT Local Hypothesis
2553         {
2554                 smeshGUI->EmitSignalDeactivateDialog();
2555                 SALOME_Selection *Sel =
2556                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2557                         getSelection());
2558                 SMESHGUI_EditHypothesesDlg *aDlg =
2559                         new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2560                 break;
2561         }
2562
2563         case 806:                                       // ORIENTATION ELEMENTS
2564         {
2565                 smeshGUI->EmitSignalDeactivateDialog();
2566                 SALOME_Selection *Sel =
2567                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2568                         getSelection());
2569                 smeshGUI->myDesktop->SetSelectionMode(3, true);
2570                 SMESHGUI_OrientationElementsDlg *aDlg =
2571                         new SMESHGUI_OrientationElementsDlg(parent, "", Sel);
2572                 break;
2573         }
2574
2575         case 807:                                       // DIAGONAL INVERSION
2576         {
2577                 smeshGUI->EmitSignalDeactivateDialog();
2578                 SALOME_Selection *Sel =
2579                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2580                         getSelection());
2581                 Sel->ClearIObjects();
2582                 smeshGUI->myDesktop->SetSelectionMode(2, true);
2583                 SMESHGUI_DiagonalInversionDlg *aDlg =
2584                         new SMESHGUI_DiagonalInversionDlg(parent, "", Sel);
2585                 break;
2586         }
2587
2588         case 900:                                       // MESH INFOS
2589         {
2590                 smeshGUI->EmitSignalDeactivateDialog();
2591                 SALOME_Selection *Sel =
2592                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2593                         getSelection());
2594                 SMESHGUI_MeshInfosDlg *aDlg =
2595                         new SMESHGUI_MeshInfosDlg(parent, "", Sel);
2596                 break;
2597         }
2598
2599         case 1001:                                      // AUTOMATIC UPDATE PREFERENCES
2600         {
2601                 parent->menuBar()->setItemChecked(1001,
2602                         !parent->menuBar()->isItemChecked(1001));
2603                 if (parent->menuBar()->isItemChecked(1001))
2604                 {
2605                         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
2606                         smeshGUI->myAutomaticUpdate = true;
2607                 }
2608                 else
2609                 {
2610                         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
2611                         smeshGUI->myAutomaticUpdate = false;
2612                 }
2613                 break;
2614         }
2615
2616         case 1003:                                      // MESH PREFERENCES
2617         {
2618                 smeshGUI->SetDisplaySettings();
2619                 break;
2620         }
2621
2622         case 1005:
2623         {
2624                 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2625                 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2626                 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2627                 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2628                 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2629                 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2630                 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2631                 int NumberOfLabels =
2632                         QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2633                 int NumberOfColors =
2634                         QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2635
2636                 if (Width == 0)
2637                         Width = 0.17;
2638                 if (Height == 0)
2639                         Height = 0.8;
2640                 if (NumberOfLabels == 0)
2641                         NumberOfLabels = 5;
2642                 if (NumberOfColors == 0)
2643                         NumberOfColors = 64;
2644
2645                 SMESHGUI_Preferences_ScalarBarDlg *aDlg =
2646                         new SMESHGUI_Preferences_ScalarBarDlg(parent, "", true);
2647
2648                 if (Bold.compare("true") == 0)
2649                         aDlg->Bold->setChecked(true);
2650                 else
2651                         aDlg->Bold->setChecked(false);
2652                 if (Italic.compare("true") == 0)
2653                         aDlg->Italic->setChecked(true);
2654                 else
2655                         aDlg->Italic->setChecked(false);
2656                 if (Shadow.compare("true") == 0)
2657   &