Salome HOME
Mounting the hypothesis LengthFromEdges in th GUI of SMESH. This
[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                         aDlg->Shadow->setChecked(true);
2658                 else
2659                         aDlg->Shadow->setChecked(false);
2660
2661                 if (Orientation.compare("Horizontal") == 0)
2662                         aDlg->RadioHoriz->setChecked(true);
2663                 else
2664                         aDlg->RadioVert->setChecked(true);
2665
2666                 int NbItems = aDlg->ComboBox1->count();
2667                 int i = 0;
2668                 aDlg->ComboBox1->setCurrentItem(i);
2669                 while (i < NbItems)
2670                 {
2671                         if (FontFamily.compare(aDlg->ComboBox1->text(i)) == 0)
2672                                 aDlg->ComboBox1->setCurrentItem(i);
2673                         i++;
2674                 }
2675
2676                 aDlg->LineEditWidth->setText(QString("%1").arg(Width));
2677                 aDlg->LineEditHeight->setText(QString("%1").arg(Height));
2678
2679                 aDlg->SpinBoxLabels->setValue(NumberOfLabels);
2680                 aDlg->SpinBoxColors->setValue(NumberOfColors);
2681
2682                 aDlg->show();
2683                 if (aDlg->result())
2684                 {
2685                         if (aDlg->RadioHoriz->isChecked())
2686                                 Orientation = "Horizontal";
2687                         else
2688                                 Orientation = "Vertical";
2689                         if (aDlg->Bold->isChecked())
2690                                 Bold = "true";
2691                         else
2692                                 Bold = "false";
2693                         if (aDlg->Italic->isChecked())
2694                                 Italic = "true";
2695                         else
2696                                 Italic = "false";
2697                         if (aDlg->Shadow->isChecked())
2698                                 Shadow = "true";
2699                         else
2700                                 Shadow = "false";
2701
2702                         FontFamily = aDlg->ComboBox1->currentText();
2703                         Width = aDlg->LineEditWidth->text().toFloat();
2704                         Height = aDlg->LineEditHeight->text().toFloat();
2705                         NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2706                         NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2707
2708                         vtkScalarBarActor *aScalarBar = smeshGUI->GetScalarBar();
2709                         if (aScalarBar != NULL)
2710                         {
2711                                 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2712                                         FontFamily, Orientation,
2713                                         Width, Height, NumberOfColors, NumberOfLabels);
2714                         }
2715
2716                         QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2717                         QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2718                         QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2719                         QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2720                         QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2721                         QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2722                         QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2723                         QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2724                         QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2725                 }
2726                 break;
2727         }
2728
2729         case 1100:                                      // EDIT HYPOTHESIS
2730         {
2731                 SALOME_Selection *Sel =
2732                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2733                         getSelection());
2734                 int nbSel = Sel->IObjectCount();
2735
2736                 if (nbSel == 1)
2737                 {
2738                         Standard_Boolean res;
2739                         SMESH::SMESH_Hypothesis_var Hyp =
2740                                 smeshGUI->ConvertIOinSMESHHypothesis(Sel->firstIObject(), res);
2741
2742                         /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2743                         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2744                         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2745                         SALOMEDS::Study::ListOfSObject_var listSOmesh =
2746                                 smeshGUI->GetMeshesUsingAlgoOrHypothesis(Hyp);
2747
2748                         if (res)
2749                         {
2750                                 QString Name = Hyp->GetName();
2751
2752                                 if (Name.compare("LocalLength") == 0)
2753                                 {
2754                                         SMESH::SMESH_LocalLength_var LL =
2755                                                 SMESH::SMESH_LocalLength::_narrow(Hyp);
2756                                         double beforeLength = LL->GetLength();
2757                                         double Length = smeshGUI->Parameter(res,
2758                                                 beforeLength,
2759                                                 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2760                                                 tr("SMESH_VALUE"),
2761                                                 1.0E-5, 1E6, 6);
2762                                         if (res && Length != beforeLength)
2763                                         {
2764                                                 LL->SetLength(Length);
2765                                                 for (int i = 0; i < listSOmesh->length(); i++)
2766                                                 {
2767                                                         smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2768                                                                 false);
2769                                                 }
2770                                                 break;
2771                                         }
2772
2773                                 }
2774                                 else if (Name.compare("NumberOfSegments") == 0)
2775                                 {
2776                                         SMESH::SMESH_NumberOfSegments_var NOS =
2777                                                 SMESH::SMESH_NumberOfSegments::_narrow(Hyp);
2778                                         int beforeNbSeg = NOS->GetNumberOfSegments();
2779                                         int NbSeg = smeshGUI->Parameter(res,
2780                                                 beforeNbSeg,
2781                                                 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2782                                                 tr("SMESH_VALUE"),
2783                                                 1, 1000000);
2784
2785                                         if (res && NbSeg != beforeNbSeg)
2786                                         {
2787                                                 NOS->SetNumberOfSegments(NbSeg);
2788                                                 for (int i = 0; i < listSOmesh->length(); i++)
2789                                                 {
2790                                                         SALOMEDS::SObject_var SO = listSOmesh[i];
2791                                                         smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2792                                                                 false);
2793                                                 }
2794                                                 break;
2795                                         }
2796
2797                                 }
2798                                 else if (Name.compare("MaxElementArea") == 0)
2799                                 {
2800                                         SMESH::SMESH_MaxElementArea_var MEA =
2801                                                 SMESH::SMESH_MaxElementArea::_narrow(Hyp);
2802                                         double beforeMaxArea = MEA->GetMaxElementArea();
2803                                         double MaxArea = smeshGUI->Parameter(res,
2804                                                 beforeMaxArea,
2805                                                 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2806                                                 tr("SMESH_VALUE"),
2807                                                 1.0E-5, 1E6, 6);
2808                                         if (res && MaxArea != beforeMaxArea)
2809                                         {
2810                                                 MEA->SetMaxElementArea(MaxArea);
2811                                                 for (int i = 0; i < listSOmesh->length(); i++)
2812                                                 {
2813                                                         smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2814                                                                 false);
2815                                                 }
2816                                                 break;
2817                                         }
2818
2819                                 }
2820                                 else if (Name.compare("MaxElementVolume") == 0)
2821                                 {
2822                                         SMESH::SMESH_MaxElementVolume_var MEV =
2823                                                 SMESH::SMESH_MaxElementVolume::_narrow(Hyp);
2824                                         double beforeMaxVolume = MEV->GetMaxElementVolume();
2825                                         double MaxVolume = smeshGUI->Parameter(res,
2826                                                 beforeMaxVolume,
2827                                                 tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"),
2828                                                 tr("SMESH_VALUE"),
2829                                                 1.0E-5, 1E6, 6);
2830                                         if (res && MaxVolume != beforeMaxVolume)
2831                                         {
2832                                                 MEV->SetMaxElementVolume(MaxVolume);
2833                                                 for (int i = 0; i < listSOmesh->length(); i++)
2834                                                 {
2835                                                         smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2836                                                                 false);
2837                                                 }
2838                                                 break;
2839                                         }
2840
2841                                 }
2842                                 else if (Name.compare("Regular_1D") == 0)
2843                                 {
2844                                 }
2845                                 else if (Name.compare("MEFISTO_2D") == 0)
2846                                 {
2847                                 }
2848                                 else
2849                                 {
2850                                 }
2851
2852                         }
2853                 }
2854                 break;
2855         }
2856
2857         case 1101:                                      // RENAME
2858         {
2859                 SALOME_Selection *Sel =
2860                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2861                         getSelection());
2862                 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2863                 for (; It.More(); It.Next())
2864                 {
2865                         Handle(SALOME_InteractiveObject) IObject = It.Value();
2866
2867                         SALOMEDS::SObject_var obj =
2868                                 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2869                         SALOMEDS::GenericAttribute_var anAttr;
2870                         SALOMEDS::AttributeName_var aName;
2871                         if (!obj->_is_nil())
2872                         {
2873                                 if (obj->FindAttribute(anAttr, "AttributeName"))
2874                                 {
2875                                         aName = SALOMEDS::AttributeName::_narrow(anAttr);
2876                                         QString newName = QString(aName->Value());
2877                                         newName =
2878                                                 SALOMEGUI_NameDlg::getName(QAD_Application::
2879                                                 getDesktop(), newName);
2880                                         if (!newName.isEmpty())
2881                                         {
2882                                                 QApplication::setOverrideCursor(Qt::waitCursor);
2883                                                 smeshGUI->myActiveStudy->renameIObject(IObject,
2884                                                         newName);
2885                                         }
2886                                         QApplication::restoreOverrideCursor();
2887                                 }
2888                         }
2889                 }
2890                 break;
2891         }
2892
2893         case 1102:                                      // REMOVE HYPOTHESIS / ALGORITHMS
2894         {
2895                 QApplication::setOverrideCursor(Qt::waitCursor);
2896                 SALOME_Selection *Sel =
2897                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2898                         getSelection());
2899                 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2900                 for (int i = 0; It.More(); It.Next(), i++)
2901                 {
2902                         Handle(SALOME_InteractiveObject) IObject = It.Value();
2903                         smeshGUI->RemoveHypothesisOrAlgorithmOnMesh(IObject);
2904                 }
2905                 Sel->ClearIObjects();
2906                 smeshGUI->myActiveStudy->updateObjBrowser(true);
2907                 QApplication::restoreOverrideCursor();
2908                 break;
2909         }
2910
2911         case 401:                                       // GEOM::EDGE
2912         {
2913                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2914                         VIEW_VTK)
2915                 {                                               //VTK
2916                         smeshGUI->EmitSignalDeactivateDialog();
2917                         SALOME_Selection *Sel =
2918                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2919                                 getSelection());
2920                         Sel->ClearIObjects();
2921                         smeshGUI->myDesktop->SetSelectionMode(1, true);
2922                         parent->menuBar()->setItemChecked(9010, false);
2923                         parent->menuBar()->setItemChecked(9011, false);
2924                         smeshGUI->ViewNodes();
2925                         SMESHGUI_AddEdgeDlg *aDlg =
2926                                 new SMESHGUI_AddEdgeDlg(parent, "", Sel);
2927                 }
2928                 else
2929                 {
2930                         QApplication::restoreOverrideCursor();
2931                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2932                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2933                                 tr("SMESH_BUT_YES"));
2934                 }
2935                 break;
2936         }
2937         case 4021:                                      // TRIANGLE
2938         {
2939                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2940                         VIEW_VTK)
2941                 {                                               //VTK
2942                         smeshGUI->EmitSignalDeactivateDialog();
2943                         SALOME_Selection *Sel =
2944                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2945                                 getSelection());
2946                         Sel->ClearIObjects();
2947                         smeshGUI->myDesktop->SetSelectionMode(1, true);
2948                         parent->menuBar()->setItemChecked(9010, false);
2949                         parent->menuBar()->setItemChecked(9011, false);
2950                         smeshGUI->ViewNodes();
2951                         SMESHGUI_AddFaceDlg *aDlg =
2952                                 new SMESHGUI_AddFaceDlg(parent, "", Sel, 3);
2953                 }
2954                 else
2955                 {
2956                         QApplication::restoreOverrideCursor();
2957                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2958                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2959                                 tr("SMESH_BUT_YES"));
2960                 }
2961                 break;
2962         }
2963         case 4022:                                      // QUAD
2964         {
2965                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2966                         VIEW_VTK)
2967                 {                                               //VTK
2968                         smeshGUI->EmitSignalDeactivateDialog();
2969                         SALOME_Selection *Sel =
2970                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2971                                 getSelection());
2972                         Sel->ClearIObjects();
2973                         smeshGUI->myDesktop->SetSelectionMode(1, true);
2974                         parent->menuBar()->setItemChecked(9010, false);
2975                         parent->menuBar()->setItemChecked(9011, false);
2976                         smeshGUI->ViewNodes();
2977                         SMESHGUI_AddFaceDlg *aDlg =
2978                                 new SMESHGUI_AddFaceDlg(parent, "", Sel, 4);
2979                 }
2980                 else
2981                 {
2982                         QApplication::restoreOverrideCursor();
2983                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2984                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2985                                 tr("SMESH_BUT_YES"));
2986                 }
2987                 break;
2988         }
2989         case 4031:                                      // TETRA
2990         {
2991                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2992                         VIEW_VTK)
2993                 {                                               //VTK
2994                         smeshGUI->EmitSignalDeactivateDialog();
2995                         SALOME_Selection *Sel =
2996                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2997                                 getSelection());
2998                         Sel->ClearIObjects();
2999                         smeshGUI->myDesktop->SetSelectionMode(1, true);
3000                         parent->menuBar()->setItemChecked(9010, false);
3001                         parent->menuBar()->setItemChecked(9011, false);
3002                         smeshGUI->ViewNodes();
3003                         SMESHGUI_AddVolumeDlg *aDlg =
3004                                 new SMESHGUI_AddVolumeDlg(parent, "", Sel, 4);
3005                 }
3006                 else
3007                 {
3008                         QApplication::restoreOverrideCursor();
3009                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3010                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3011                                 tr("SMESH_BUT_YES"));
3012                 }
3013                 break;
3014         }
3015         case 4032:                                      // HEXA
3016         {
3017                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3018                         VIEW_VTK)
3019                 {                                               //VTK
3020                         smeshGUI->EmitSignalDeactivateDialog();
3021                         SALOME_Selection *Sel =
3022                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3023                                 getSelection());
3024                         Sel->ClearIObjects();
3025                         smeshGUI->myDesktop->SetSelectionMode(1, true);
3026                         parent->menuBar()->setItemChecked(9010, false);
3027                         parent->menuBar()->setItemChecked(9011, false);
3028                         smeshGUI->ViewNodes();
3029                         SMESHGUI_AddVolumeDlg *aDlg =
3030                                 new SMESHGUI_AddVolumeDlg(parent, "", Sel, 8);
3031                 }
3032                 else
3033                 {
3034                         QApplication::restoreOverrideCursor();
3035                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3036                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3037                                 tr("SMESH_BUT_YES"));
3038                 }
3039                 break;
3040         }
3041
3042         case 4041:                                      // REMOVES NODES
3043         {
3044                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3045                         VIEW_VTK)
3046                 {                                               //VTK
3047                         smeshGUI->EmitSignalDeactivateDialog();
3048                         SALOME_Selection *Sel =
3049                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3050                                 getSelection());
3051                         Sel->ClearIObjects();
3052                         smeshGUI->myDesktop->SetSelectionMode(1, true);
3053                         parent->menuBar()->setItemChecked(9010, false);
3054                         parent->menuBar()->setItemChecked(9011, false);
3055                         smeshGUI->ViewNodes();
3056                         SMESHGUI_RemoveNodesDlg *aDlg =
3057                                 new SMESHGUI_RemoveNodesDlg(parent, "", Sel);
3058                 }
3059                 else
3060                 {
3061                         QApplication::restoreOverrideCursor();
3062                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3063                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3064                                 tr("SMESH_BUT_YES"));
3065                 }
3066                 break;
3067         }
3068         case 4042:                                      // REMOVES ELEMENTS
3069         {
3070                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3071                         VIEW_VTK)
3072                 {                                               //VTK
3073                         smeshGUI->EmitSignalDeactivateDialog();
3074                         SALOME_Selection *Sel =
3075                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3076                                 getSelection());
3077                         Sel->ClearIObjects();
3078                         smeshGUI->myDesktop->SetSelectionMode(3, true);
3079                         SMESHGUI_RemoveElementsDlg *aDlg =
3080                                 new SMESHGUI_RemoveElementsDlg(parent, "", Sel);
3081                 }
3082                 else
3083                 {
3084                         QApplication::restoreOverrideCursor();
3085                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3086                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3087                                 tr("SMESH_BUT_YES"));
3088                 }
3089                 break;
3090         }
3091
3092         case 5000:                                      // HYPOTHESIS - ALGO
3093         {
3094                 smeshGUI->CreateAlgorithm("Regular_1D", "Wire Discretisation");
3095                 break;
3096         }
3097         case 5010:
3098         {
3099                 smeshGUI->CreateAlgorithm("MEFISTO_2D", "Triangle (Mefisto)");
3100                 break;
3101         }
3102         case 5011:
3103         {
3104                 smeshGUI->CreateAlgorithm("Quadrangle_2D", "Quadrangle (Mapping)");
3105                 break;
3106         }
3107         case 5020:
3108         {
3109                 smeshGUI->CreateAlgorithm("Hexa_3D", "Hexahedron (i,j,k)");
3110                 break;
3111         }
3112         case 5021:
3113         {
3114                 smeshGUI->CreateAlgorithm("NETGEN_3D", "Tetrahedron (Netgen)");
3115                 break;
3116         }
3117
3118         case 5030:                                      // HYPOTHESIS - LOCAL LENGTH
3119         {
3120                 smeshGUI->EmitSignalDeactivateDialog();
3121                 SALOME_Selection *Sel =
3122                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3123                         getSelection());
3124                 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg(parent, "");
3125                 break;
3126         }
3127         case 5031:                                      // HYPOTHESIS - NB SEGMENTS
3128         {
3129                 smeshGUI->EmitSignalDeactivateDialog();
3130                 SALOME_Selection *Sel =
3131                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3132                         getSelection());
3133                 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg(parent, "");
3134                 break;
3135         }
3136
3137         case 5032:                                      // HYPOTHESIS - MAX ELEMENT AREA
3138         {
3139                 smeshGUI->EmitSignalDeactivateDialog();
3140                 SALOME_Selection *Sel =
3141                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3142                         getSelection());
3143                 SMESHGUI_MaxElementAreaDlg *aDlg =
3144                         new SMESHGUI_MaxElementAreaDlg(parent, "");
3145                 break;
3146         }
3147
3148         case 5033:                                      // HYPOTHESIS - MAX ELEMENT VOLUME
3149         {
3150                 smeshGUI->EmitSignalDeactivateDialog();
3151                 SALOME_Selection *Sel =
3152                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3153                         getSelection());
3154                 SMESHGUI_MaxElementVolumeDlg *aDlg =
3155                         new SMESHGUI_MaxElementVolumeDlg(parent, "");
3156                 break;
3157         }
3158
3159         case 5034:                                     // HYPOTHESIS - LENGTH FROM EDGES
3160         {
3161           SMESH::SMESH_Hypothesis_var Hyp;
3162           try
3163             {
3164               Hyp = smeshGUI->myComponentMesh->CreateHypothesis("LengthFromEdges", smeshGUI->myStudyId);
3165
3166               if (!Hyp->_is_nil())
3167                 {
3168                   SALOMEDS::SObject_var SHyp = smeshGUI->myStudyAPI.AddNewHypothesis(Hyp);
3169                   smeshGUI->myStudyAPI.SetName(SHyp, "LengthFromEdges");
3170                 }
3171             }
3172           catch(const SALOME::SALOME_Exception & S_ex)
3173             {
3174               QtCatchCorbaException(S_ex);
3175             }
3176           smeshGUI->myActiveStudy->updateObjBrowser(true);
3177
3178           break;
3179         }
3180
3181         case 6016:                                      // CONTROLS 
3182         case 6015:
3183         case 6014:
3184         case 6013:
3185         case 6012:
3186         case 6011:
3187         case 6001:
3188         {
3189                 SALOME_Selection *Sel =
3190                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3191                         getSelection());
3192                 int nbSel = Sel->IObjectCount();
3193                 if (nbSel != 1)
3194                         break;
3195                 smeshGUI->Control(theCommandID);
3196                 break;
3197         }
3198
3199         case 6002:
3200         {
3201                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3202                         VIEW_VTK)
3203                 {                                               //VTK
3204                         SALOME_Selection *Sel =
3205                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3206                                 getSelection());
3207                         SMESHGUI_EdgesConnectivityDlg *Dlg =
3208                                 new SMESHGUI_EdgesConnectivityDlg(parent, "", Sel);
3209                 }
3210                 else
3211                 {
3212                         QApplication::restoreOverrideCursor();
3213                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3214                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3215                                 tr("SMESH_BUT_YES"));
3216                 }
3217                 break;
3218         }
3219
3220         case 9010:
3221         {
3222                 if (!parent->menuBar()->isItemChecked(9010))
3223                 {
3224                         QApplication::setOverrideCursor(Qt::waitCursor);
3225                         parent->menuBar()->setItemChecked(9011, false);
3226
3227                         smeshGUI->EraseSimulationActors();
3228                         smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
3229
3230                         SALOME_Selection *Sel =
3231                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3232                                 getSelection());
3233                         int nbSel = Sel->IObjectCount();
3234                         if (nbSel == 1)
3235                         {
3236                                 Standard_Boolean res;
3237                                 SMESH_Actor *MeshActor =
3238                                         smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(),
3239                                         res, true);
3240                                 if (res)
3241                                 {
3242                                         parent->menuBar()->setItemChecked(9010,
3243                                                 !parent->menuBar()->isItemChecked(9010));
3244
3245                                         // It's necessary to display SMDS IDs instead of VTK ones, so 
3246                                         // vtkIdFilter is unacceptable here. We have to do it manually :(
3247                                         vtkUnstructuredGrid *ptGrid = vtkUnstructuredGrid::New();
3248                                         ptGrid->CopyStructure(MeshActor->DataSource);
3249
3250                                         int numPts = MeshActor->DataSource->GetNumberOfPoints();
3251
3252                                         // Loop over points and generate ids
3253                                         vtkIntArray *ptIds = vtkIntArray::New();
3254                                         ptIds->SetNumberOfValues(numPts);
3255
3256                                         for (int id = 0; id < numPts; id++)
3257                                         {
3258                                                 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
3259                                                 ptIds->SetValue(id, idSMDS);
3260                                         }
3261
3262 // mpv porting vtk4.2.2
3263                                         //          vtkScalars* newScalars = vtkScalars::New();
3264                                         //          newScalars->SetData(ptIds);
3265                                         //          ptGrid->GetPointData()->SetScalars(newScalars);
3266                                         ptGrid->GetPointData()->SetScalars(ptIds);
3267                                         //          newScalars->Delete();
3268 // mpv
3269                                         ptIds->Delete();
3270
3271                                         vtkMaskPoints *mask = vtkMaskPoints::New();
3272                                         mask->SetInput(ptGrid);
3273                                         mask->SetOnRatio(1);
3274                                         //        mask->SetMaximumNumberOfPoints( 50 );
3275                                         //        mask->RandomModeOn();
3276
3277                                         vtkSelectVisiblePoints *visPts =
3278                                                 vtkSelectVisiblePoints::New();
3279                                         visPts->SetInput(mask->GetOutput());
3280                                         visPts->SetRenderer(((VTKViewer_ViewFrame *) smeshGUI->
3281                                                         myActiveStudy->getActiveStudyFrame()->
3282                                                         getRightFrame()->getViewFrame())->getRenderer());
3283                                         //visPts->SetSelectInvisible(1);
3284                                         visPts->SelectInvisibleOff();
3285                                         visPts->SetTolerance(0.1);
3286
3287                                         vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
3288                                         ldm->SetInput(visPts->GetOutput());
3289                                         ldm->SetLabelFormat("%g");
3290                                         ldm->SetLabelModeToLabelScalars();
3291                                         //ldm->SetLabelModeToLabelFieldData();
3292
3293                                         ldm->SetFontFamilyToTimes();
3294                                         ldm->SetFontSize(6 * parent->font().pointSize() / 5);
3295                                         ldm->SetBold(1);
3296                                         ldm->SetItalic(0);
3297                                         ldm->SetShadow(0);
3298
3299                                         vtkActor2D *pointLabels = vtkActor2D::New();
3300                                         pointLabels->SetMapper(ldm);
3301                                         pointLabels->GetProperty()->SetColor(0, 1, 0);
3302
3303                                         visPts->Delete();
3304                                         ldm->Delete();
3305                                         smeshGUI->mySimulationActors2D->AddItem(pointLabels);
3306                                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
3307                                                 getActiveStudyFrame()->getRightFrame()->
3308                                                 getViewFrame())->getRenderer()->AddActor2D(pointLabels);
3309                                 }
3310                         }
3311                 }
3312                 else
3313                 {
3314                         QApplication::setOverrideCursor(Qt::waitCursor);
3315                         parent->menuBar()->setItemChecked(9010,
3316                                 !parent->menuBar()->isItemChecked(9010));
3317                         smeshGUI->EraseSimulationActors();
3318                         smeshGUI->ScalarVisibilityOff();
3319                 }
3320                 QApplication::restoreOverrideCursor();
3321                 break;
3322         }
3323         case 9011:
3324         {
3325                 if (!parent->menuBar()->isItemChecked(9011))
3326                 {
3327                         QApplication::setOverrideCursor(Qt::waitCursor);
3328                         parent->menuBar()->setItemChecked(9010, false);
3329
3330                         smeshGUI->EraseSimulationActors();
3331                         smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
3332
3333                         SALOME_Selection *Sel =
3334                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3335                                 getSelection());
3336                         int nbSel = Sel->IObjectCount();
3337                         if (nbSel == 1)
3338                         {
3339                                 Standard_Boolean res;
3340                                 SMESH_Actor *MeshActor =
3341                                         smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(),
3342                                         res, true);
3343                                 if (res)
3344                                 {
3345                                         parent->menuBar()->setItemChecked(9011,
3346                                                 !parent->menuBar()->isItemChecked(9011));
3347
3348                                         // It's necessary to display SMDS IDs instead of VTK ones, so 
3349                                         // vtkIdFilter is unacceptable here. We have to do it manually :(
3350                                         vtkUnstructuredGrid *elGrid = vtkUnstructuredGrid::New();
3351                                         elGrid->CopyStructure(MeshActor->DataSource);
3352
3353                                         int numCells = MeshActor->DataSource->GetNumberOfCells();
3354
3355                                         // Loop over points and generate ids
3356                                         vtkIntArray *cellIds = vtkIntArray::New();
3357                                         cellIds->SetNumberOfValues(numCells);
3358
3359                                         for (int id = 0; id < numCells; id++)
3360                                         {
3361                                                 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
3362                                                 cellIds->SetValue(id, idSMDS);
3363                                         }
3364
3365 // mpv porting vk4.2.2
3366                                         //          vtkScalars* newScalars = vtkScalars::New();
3367                                         //          newScalars->SetData(cellIds);
3368                                         elGrid->GetCellData()->SetScalars(cellIds);
3369                                         //          elGrid->GetCellData()->SetScalars(newScalars);
3370                                         //          newScalars->Delete();
3371 //mpv
3372
3373                                         cellIds->Delete();
3374
3375                                         vtkCellCenters *cc = vtkCellCenters::New();
3376                                         cc->SetInput(elGrid);
3377
3378                                         vtkSelectVisiblePoints *visCells =
3379                                                 vtkSelectVisiblePoints::New();
3380                                         visCells->SetInput(cc->GetOutput());
3381                                         visCells->SetRenderer(((VTKViewer_ViewFrame *) smeshGUI->
3382                                                         myActiveStudy->getActiveStudyFrame()->
3383                                                         getRightFrame()->getViewFrame())->getRenderer());
3384                                         visCells->SelectInvisibleOff();
3385                                         visCells->SetTolerance(0.1);
3386                                         //        visCells->SetSelectInvisible(1);
3387
3388                                         vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
3389                                         ldm->SetInput(visCells->GetOutput());
3390                                         ldm->SetLabelFormat("%g");
3391                                         ldm->SetLabelModeToLabelScalars();
3392
3393                                         ldm->SetFontFamilyToTimes();
3394                                         ldm->SetFontSize(6 * parent->font().pointSize() / 5);
3395                                         ldm->SetBold(1);
3396                                         ldm->SetItalic(0);
3397                                         ldm->SetShadow(0);
3398
3399                                         vtkActor2D *cellLabels = vtkActor2D::New();
3400                                         cellLabels->SetMapper(ldm);
3401                                         cellLabels->GetProperty()->SetColor(1, 0, 0);
3402
3403                                         cc->Delete();
3404                                         visCells->Delete();
3405                                         ldm->Delete();
3406                                         smeshGUI->mySimulationActors2D->AddItem(cellLabels);
3407                                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
3408                                                 getActiveStudyFrame()->getRightFrame()->
3409                                                 getViewFrame())->getRenderer()->AddActor2D(cellLabels);
3410                                 }
3411                         }
3412                 }
3413                 else
3414                 {
3415                         QApplication::setOverrideCursor(Qt::waitCursor);
3416                         parent->menuBar()->setItemChecked(9011,
3417                                 !parent->menuBar()->isItemChecked(9011));
3418                         smeshGUI->EraseSimulationActors();
3419                         smeshGUI->ScalarVisibilityOff();
3420                 }
3421                 QApplication::restoreOverrideCursor();
3422                 break;
3423         }
3424
3425         case 10001:                             // DISPLAY MODE PREFERENCE
3426         {
3427                 parent->menuBar()->setItemChecked(10001,
3428                         !parent->menuBar()->isItemChecked(10001));
3429                 parent->menuBar()->setItemChecked(10002, false);
3430                 parent->menuBar()->setItemChecked(10003, false);
3431                 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
3432                 break;
3433         }
3434         case 10002:
3435         {
3436                 parent->menuBar()->setItemChecked(10002,
3437                         !parent->menuBar()->isItemChecked(10002));
3438                 parent->menuBar()->setItemChecked(10001, false);
3439                 parent->menuBar()->setItemChecked(10003, false);
3440                 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3441                 break;
3442         }
3443         case 10003:
3444         {
3445                 parent->menuBar()->setItemChecked(10003,
3446                         !parent->menuBar()->isItemChecked(10003));
3447                 parent->menuBar()->setItemChecked(10002, false);
3448                 parent->menuBar()->setItemChecked(10001, false);
3449                 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
3450                 break;
3451         }
3452
3453         }
3454
3455         smeshGUI->myActiveStudy->updateObjBrowser(true);
3456         return true;
3457 }
3458
3459 //=============================================================================
3460 /*! function : GetMeshesUsingAlgoOrHypothesis()
3461  *  purpose  : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
3462  *           : However is supposed here that father of father of an hypothesis is a Mesh Object.
3463  */
3464 //=============================================================================      
3465 SALOMEDS::Study::ListOfSObject *
3466         SMESHGUI::GetMeshesUsingAlgoOrHypothesis(SMESH::
3467         SMESH_Hypothesis_ptr AlgoOrHyp)
3468 {
3469         SALOMEDS::Study::ListOfSObject_var listSOmesh =
3470                 new SALOMEDS::Study::ListOfSObject;
3471         listSOmesh->length(0);
3472         unsigned int index = 0;
3473         if (!AlgoOrHyp->_is_nil())
3474         {
3475                 SALOMEDS::SObject_var SO_Hypothesis =
3476                         smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms(AlgoOrHyp);
3477                 if (!SO_Hypothesis->_is_nil())
3478                 {
3479                         SALOMEDS::Study::ListOfSObject_var listSO =
3480                                 smeshGUI->myStudy->FindDependances(SO_Hypothesis);
3481                         for (unsigned int i = 0; i < listSO->length(); i++)
3482                         {
3483                                 SALOMEDS::SObject_var SO = listSO[i];
3484                                 if (!SO->_is_nil())
3485                                 {
3486                                         SALOMEDS::SObject_var SOfatherFather =
3487                                                 SO->GetFather()->GetFather();
3488                                         if (!SOfatherFather->_is_nil())
3489                                         {
3490                                                 index++;
3491                                                 listSOmesh->length(index);
3492                                                 listSOmesh[index - 1] = SOfatherFather;
3493                                         }
3494                                 }
3495                         }
3496                 }
3497         }
3498         return listSOmesh._retn();
3499 }
3500
3501 //=============================================================================
3502 /*!
3503  *
3504  */
3505 //=============================================================================
3506 void SMESHGUI::Import_Mesh(QAD_Desktop * parent, int theCommandID)
3507 {
3508         QString filter;
3509         string myExtension;
3510         Mesh_Reader *myReader;
3511
3512         if (theCommandID == 113)
3513         {
3514                 filter = tr("MED files (*.med)");
3515                 myExtension = string("MED");
3516                 myReader = new DriverMED_R_SMESHDS_Mesh;
3517         }
3518         else if (theCommandID == 112)
3519         {
3520                 filter = tr("IDEAS files (*.unv)");
3521                 myExtension = string("UNV");
3522         }
3523         else if (theCommandID == 111)
3524         {
3525                 filter = tr("DAT files (*.dat)");
3526                 myExtension = string("MED");
3527                 myReader = new DriverDAT_R_SMESHDS_Mesh;
3528         }
3529
3530         QString filename = QAD_FileDlg::getFileName(parent,
3531                 "",
3532                 filter,
3533                 tr("Import mesh"),
3534                 true);
3535         if (!filename.isEmpty())
3536         {
3537                 QApplication::setOverrideCursor(Qt::waitCursor);
3538                 string myClass = string("SMESHDS_Mesh");
3539 //    Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
3540
3541                 int myMeshId = (smeshGUI->myDocument)->NewMesh();
3542                 SMDS_Mesh *myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
3543
3544                 myReader->SetFile(string(filename.latin1()));
3545                 myReader->SetMesh(myMesh);
3546                 myReader->SetMeshId(myMeshId);
3547                 myReader->Read();
3548
3549                 QApplication::restoreOverrideCursor();
3550         }
3551 }
3552
3553 //=============================================================================
3554 /*!
3555  *
3556  */
3557 //=============================================================================
3558 void SMESHGUI::Export_Mesh(QAD_Desktop * parent, int theCommandID)
3559 {
3560         SALOME_Selection *Sel =
3561                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3562         int nbSel = Sel->IObjectCount();
3563         if (nbSel == 1)
3564         {
3565                 Standard_Boolean res;
3566                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3567                 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(IObject, res);
3568                 if (res)
3569                 {
3570                         if (theCommandID == 122)
3571                         {                                       // EXPORT MED
3572                                 QString filename = QAD_FileDlg::getFileName(parent,
3573                                         "",
3574                                         tr("MED files (*.med)"),
3575                                         tr("Export mesh"),
3576                                         false);
3577                                 if (!filename.isEmpty())
3578                                 {
3579                                         QApplication::setOverrideCursor(Qt::waitCursor);
3580                                         aMesh->ExportMED(filename.latin1());
3581                                         QApplication::restoreOverrideCursor();
3582                                 }
3583                         }
3584                         else if (theCommandID == 121)
3585                         {                                       // EXPORT DAT
3586                                 QString filename = QAD_FileDlg::getFileName(parent,
3587                                         "",
3588                                         tr("DAT files (*.dat)"),
3589                                         tr("Export mesh"),
3590                                         false);
3591                                 if (!filename.isEmpty())
3592                                 {
3593                                         QApplication::setOverrideCursor(Qt::waitCursor);
3594                                         aMesh->ExportDAT(filename.latin1());
3595                                         QApplication::restoreOverrideCursor();
3596                                 }
3597                         }
3598                         else if (theCommandID == 123)
3599                         {                                       // EXPORT UNV
3600                                 QString filename = QAD_FileDlg::getFileName(parent,
3601                                         "",
3602                                         tr("IDEAS files (*.unv)"),
3603                                         tr("Export mesh"),
3604                                         false);
3605                                 if (!filename.isEmpty())
3606                                 {
3607                                         QApplication::setOverrideCursor(Qt::waitCursor);
3608                                         aMesh->ExportUNV(filename.latin1());
3609                                         QApplication::restoreOverrideCursor();
3610                                 }
3611                                 else
3612                                         aMesh->ExportDAT(filename.latin1());
3613
3614                                 QApplication::restoreOverrideCursor();
3615
3616                                 if (IObject->hasEntry())
3617                                 {
3618                                         MESSAGE("---");
3619                                         SALOMEDS::SObject_var SO =
3620                                                 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
3621                                         SALOMEDS::GenericAttribute_var anAttr;
3622                                         SALOMEDS::AttributeComment_var aFileName;
3623                                         SALOMEDS::StudyBuilder_var aStudyBuilder =
3624                                                 smeshGUI->myStudy->NewBuilder();
3625                                         anAttr =
3626                                                 aStudyBuilder->FindOrCreateAttribute(SO,
3627                                                 "AttributeComment");
3628                                         aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
3629                                         aFileName->SetValue(filename.latin1());
3630                                 }
3631                         }
3632                 }
3633         }
3634 }
3635
3636 //=============================================================================
3637 /*!
3638  *
3639  */
3640 //=============================================================================
3641 void SMESHGUI::Import_Document(QAD_Desktop * parent, int theCommandID)
3642 {
3643         QString filter;
3644         string myExtension;
3645         Document_Reader *myReader;
3646
3647         if (theCommandID == 113)
3648         {
3649                 filter = tr("MED files (*.med)");
3650                 myExtension = string("MED");
3651                 myReader = new DriverMED_R_SMESHDS_Document;
3652         }
3653         else if (theCommandID == 112)
3654         {
3655                 filter = tr("IDEAS files (*.unv)");
3656                 myExtension = string("UNV");
3657                 myReader = new DriverUNV_R_SMESHDS_Document;
3658         }
3659         else if (theCommandID == 111)
3660         {
3661                 filter = tr("DAT files (*.dat)");
3662                 myExtension = string("DAT");
3663                 myReader = new DriverDAT_R_SMESHDS_Document;
3664         }
3665
3666         QString filename = QAD_FileDlg::getFileName(parent,
3667                 "",
3668                 filter,
3669                 tr("Import document"),
3670                 true);
3671         if (!filename.isEmpty())
3672         {
3673                 QApplication::setOverrideCursor(Qt::waitCursor);
3674                 string myClass = string("SMESHDS_Document");
3675 //    Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
3676                 SMESHDS_Document *newDocument = new SMESHDS_Document(1);
3677
3678                 myReader->SetFile(string(filename.latin1()));
3679                 myReader->SetDocument(smeshGUI->myDocument);
3680                 myReader->Read();
3681                 QApplication::restoreOverrideCursor();
3682         }
3683 }
3684
3685 void SMESHGUI::Export_Document(QAD_Desktop * parent, int theCommandID)
3686 {
3687         QString filter;
3688         Document_Writer *myWriter;
3689         string myExtension;
3690
3691         if (theCommandID == 122)
3692         {
3693                 filter = tr("MED files (*.med)");
3694                 myExtension = string("MED");
3695                 myWriter = new DriverMED_W_SMESHDS_Document;
3696         }
3697         else if (theCommandID == 121)
3698         {
3699                 filter = tr("DAT files (*.dat)");
3700                 myExtension = string("DAT");
3701                 myWriter = new DriverDAT_W_SMESHDS_Document;
3702         }
3703         else if (theCommandID == 123)
3704         {
3705                 filter = tr("IDEAS files (*.unv)");
3706                 myExtension = string("UNV");
3707                 myWriter = new DriverUNV_W_SMESHDS_Document;
3708         }
3709
3710         QString filename = QAD_FileDlg::getFileName(parent,
3711                 "",
3712                 filter,
3713                 tr("Export document"),
3714                 false);
3715         if (!filename.isEmpty())
3716         {
3717                 QApplication::setOverrideCursor(Qt::waitCursor);
3718                 string myClass = string("SMESHDS_Document");
3719                 //Document_Writer* myWriter = SMESHDriver::GetDocumentWriter(myExtension, myClass);
3720
3721                 myWriter->SetFile(string(filename.latin1()));
3722                 myWriter->SetDocument(smeshGUI->myDocument);
3723
3724                 //StudyContextStruct* myStudyContext = _impl.GetStudyContext(myStudyId);
3725                 //Handle(SMESHDS_Document) myDocument = myStudyContext->myDocument;
3726                 //myWriter->SetDocument(myDocument);
3727
3728                 myWriter->Write();
3729                 QApplication::restoreOverrideCursor();
3730         }
3731 }
3732
3733 //=============================================================================
3734 /*!
3735  *
3736  */
3737 //=============================================================================
3738 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3739         QAD_StudyFrame * studyFrame)
3740 {
3741         SMESHGUI::GetOrCreateSMESHGUI(parent);
3742         return false;
3743 }
3744
3745 //=============================================================================
3746 /*!
3747  *
3748  */
3749 //=============================================================================
3750 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3751         QAD_StudyFrame * studyFrame)
3752 {
3753         SMESHGUI::GetOrCreateSMESHGUI(parent);
3754
3755         return true;
3756 }
3757
3758 //=============================================================================
3759 /*!
3760  *
3761  */
3762 //=============================================================================
3763 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3764         QAD_StudyFrame * studyFrame)
3765 {
3766         SMESHGUI::GetOrCreateSMESHGUI(parent);
3767
3768         return true;
3769 }
3770
3771 //=============================================================================
3772 /*!
3773  *
3774  */
3775 //=============================================================================
3776 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
3777 {
3778         SMESHGUI::GetOrCreateSMESHGUI(parent);
3779
3780         /* Display mode */
3781         QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3782         if (DisplayMode.compare("") == 0)
3783         {
3784                 DisplayMode = "Shading";
3785                 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3786         }
3787
3788         if (DisplayMode.compare("Wireframe") == 0)
3789         {
3790                 parent->menuBar()->setItemChecked(10003, false);
3791                 parent->menuBar()->setItemChecked(10002, false);
3792                 parent->menuBar()->setItemChecked(10001, true);
3793         }
3794         else if (DisplayMode.compare("Shading") == 0)
3795         {
3796                 parent->menuBar()->setItemChecked(10003, false);
3797                 parent->menuBar()->setItemChecked(10002, true);
3798                 parent->menuBar()->setItemChecked(10001, false);
3799         }
3800         else if (DisplayMode.compare("Shrink") == 0)
3801         {
3802                 parent->menuBar()->setItemChecked(10003, true);
3803                 parent->menuBar()->setItemChecked(10002, false);
3804                 parent->menuBar()->setItemChecked(10001, false);
3805         }
3806
3807         /* Automatic Update */
3808         QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3809         if (AutoUpdate.compare("true") == 0)
3810         {
3811                 parent->menuBar()->setItemChecked(1001, true);
3812                 smeshGUI->myAutomaticUpdate = true;
3813         }
3814         else
3815         {
3816                 parent->menuBar()->setItemChecked(1001, false);
3817                 smeshGUI->myAutomaticUpdate = false;
3818         }
3819
3820         /* menus disable */
3821         parent->menuBar()->setItemEnabled(11, false);   // IMPORT
3822
3823         return true;
3824 }
3825
3826 //=============================================================================
3827 /*!
3828  *
3829  */
3830 //=============================================================================
3831 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent,
3832         QString & theObject)
3833 {
3834         /* Create or retrieve an object SMESHGUI */
3835         SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3836
3837         // NRI : Temporary added
3838         //  if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3839         //    theObject = "NothingSelected";
3840         //    theContext = "NothingSelected";
3841         //  }
3842         // NRI
3843
3844         SALOME_Selection *Sel =
3845                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3846         int nbSel = Sel->IObjectCount();
3847         if (nbSel == 0)
3848         {
3849                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3850                         VIEW_VTK)
3851                 {
3852                         vtkScalarBarActor *aScalarBar = smeshGUI->GetScalarBar();
3853                         if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1))
3854                         {
3855                                 theObject = "ScalarBar";
3856                                 theContext = "";
3857                         }
3858                         else
3859                         {
3860                                 theObject = "NothingSelected";
3861                                 theContext = "NothingSelected";
3862                         }
3863                 }
3864                 else
3865                 {
3866                         theObject = "NothingSelected";
3867                         theContext = "NothingSelected";
3868                 }
3869         }
3870         else if (nbSel == 1)
3871         {
3872                 theObject = smeshGUI->CheckTypeObject(Sel->firstIObject());
3873                 theContext = "";
3874         }
3875         else
3876         {
3877                 theObject = smeshGUI->CheckHomogeneousSelection();
3878                 theContext = "";
3879         }
3880 }
3881
3882 //=============================================================================
3883 /*!
3884  *
3885  */
3886 //=============================================================================
3887 bool SMESHGUI::CustomPopup(QAD_Desktop * parent,
3888         QPopupMenu * popup,
3889         const QString & theContext,
3890         const QString & theParent, const QString & theObject)
3891 {
3892         // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3893         //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3894         //  return false;
3895         /* Create or retrieve an object SMESHGUI */
3896         SMESHGUI::GetOrCreateSMESHGUI(parent);
3897
3898         // NRI : Temporary added
3899         //  if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3900         //    return false;
3901         //  }
3902         // NRI
3903
3904         SALOME_Selection *Sel =
3905                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3906         QAD_StudyFrame *studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3907         int nbSel = Sel->IObjectCount();
3908
3909         if (nbSel == 0)
3910         {
3911                 if (studyFrame->getTypeView() != VIEW_VTK)
3912                         popup->clear();
3913                 return false;
3914         }
3915         else if (nbSel == 1)
3916         {
3917                 QString parentComp =
3918                         ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
3919                 // First check type of active viewer (VTK required)
3920                 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
3921                         parent->getActiveComponent())
3922                 {
3923                         //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3924                         while (1)
3925                         {
3926                                 int id = popup->idAt(0);
3927                                 if (id <= QAD_TopLabel_Popup_ID)
3928                                         popup->removeItemAt(0);
3929                                 else
3930                                         break;
3931                         }
3932                         if (theObject.compare("Component") == 0)
3933                         {
3934                                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3935                         }
3936                         return false;
3937                 }
3938
3939                 // Remove common popup items for Submesh, Hypothesis and Algorithm
3940                 if (theObject.compare("SubMesh") == 0 ||
3941                         theObject.compare("Hypothesis") == 0 ||
3942                         theObject.compare("Algorithm") == 0)
3943                 {
3944                         popup->removeItem(QAD_Display_Popup_ID);
3945                         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3946                         popup->removeItem(QAD_Erase_Popup_ID);
3947                         int id = popup->idAt(popup->count() - 1);       // last item
3948                         if (id < 0 && id != -1)
3949                                 popup->removeItem(id);  // separator
3950                 }
3951
3952                 if (theObject.compare("Component") == 0)
3953                 {
3954                         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3955                         return true;
3956                 }
3957
3958                 int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
3959                 QFont f = QApplication::font();
3960                 f.setBold(TRUE);
3961
3962                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3963
3964                 if (theParent.compare("Viewer") == 0)
3965                 {
3966                         if (popup->idAt(0) == id)
3967                         {
3968                                 popup->removeItem(id);
3969                                 popup->insertItem(new CustomItem(QString(IObject->getName()),
3970                                                 f), id, 0);
3971                         }
3972
3973                         Standard_Boolean res;
3974                         SMESH_Actor *ac =
3975                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3976                         if (res && studyFrame->getTypeView() == VIEW_VTK)
3977                         {
3978                                 VTKViewer_RenderWindowInteractor *myRenderInter =
3979                                         ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
3980                                         getViewFrame())->getRWInteractor();
3981                                 if (myRenderInter->isVisible(IObject))
3982                                 {
3983                                         popup->removeItem(QAD_Display_Popup_ID);
3984                                 }
3985                                 else
3986                                 {
3987                                         popup->removeItem(QAD_Erase_Popup_ID);
3988                                 }
3989                         }
3990                         else
3991                         {
3992                                 popup->removeItem(QAD_Erase_Popup_ID);
3993                                 if (!res)
3994                                 {                               // mesh not computed -> can't display it
3995                                         popup->removeItem(QAD_Display_Popup_ID);
3996                                         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3997                                         popup->removeItemAt(popup->count() - 1);        //separator
3998                                 }
3999                         }
4000                 }
4001                 else if (theParent.compare("ObjectBrowser") == 0)
4002                 {
4003                         if (theObject.compare("Mesh") == 0 ||
4004                                 theObject.compare("SubMesh") == 0 ||
4005                                 theObject.compare("Hypothesis") == 0 ||
4006                                 theObject.compare("Algorithm") == 0)
4007                         {
4008                                 popup->removeItemAt(0);
4009                         }
4010                         else
4011                         {
4012                                 if (popup->idAt(0) == id)
4013                                 {
4014                                         popup->removeItem(id);
4015                                         popup->removeItemAt(0); //separator
4016                                 }
4017                         }
4018
4019                         Standard_Boolean res;
4020                         SMESH_Actor *ac =
4021                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
4022                         if (res && studyFrame->getTypeView() == VIEW_VTK)
4023                         {
4024                                 VTKViewer_RenderWindowInteractor *myRenderInter =
4025                                         ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
4026                                         getViewFrame())->getRWInteractor();
4027                                 if (myRenderInter->isVisible(IObject))
4028                                 {
4029                                         popup->removeItem(QAD_Display_Popup_ID);
4030                                 }
4031                                 else
4032                                 {
4033                                         popup->removeItem(QAD_Erase_Popup_ID);
4034                                 }
4035                         }
4036                         else
4037                         {
4038                                 if (theObject.compare("Mesh") == 0 ||
4039                                         theObject.compare("SubMesh") == 0 ||
4040                                         theObject.compare("Hypothesis") == 0 ||
4041                                         theObject.compare("Algorithm") == 0)
4042                                 {
4043                                 }
4044                                 else
4045                                 {
4046                                         popup->removeItem(QAD_Erase_Popup_ID);
4047                                         if (!res)
4048                                         {                       // mesh not computed -> can't display it
4049                                                 popup->removeItem(QAD_Display_Popup_ID);
4050                                                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
4051                                                 popup->removeItemAt(popup->count() - 1);        //separator
4052                                         }
4053                                 }
4054                         }
4055                 }
4056         }
4057         else
4058         {
4059                 QString parentComp =
4060                         ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
4061                 QAD_StudyFrame *studyFrame =
4062                         smeshGUI->myActiveStudy->getActiveStudyFrame();
4063                 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
4064                         parent->getActiveComponent())
4065                 {
4066                         //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
4067                         while (1)
4068                         {
4069                                 int id = popup->idAt(0);
4070                                 if (id <= QAD_TopLabel_Popup_ID && id != -1)
4071                                         popup->removeItemAt(0);
4072                                 else
4073                                         break;
4074                         }
4075                         if (parentComp.isNull())
4076                         {                                       // objects from several components are selected
4077                                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
4078                                 popup->removeItem(QAD_Display_Popup_ID);
4079                                 popup->removeItem(QAD_Erase_Popup_ID);
4080                                 int id = popup->idAt(popup->count() - 1);       // last item
4081                                 if (id < 0 && id != -1)
4082                                         popup->removeItem(id);  // separator
4083                         }
4084                         return false;
4085                 }
4086
4087                 QString type = smeshGUI->CheckHomogeneousSelection();
4088                 if (type.compare("Heterogeneous Selection") != 0)
4089                 {
4090                         int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
4091                         QFont f = QApplication::font();
4092                         f.setBold(TRUE);
4093                         popup->removeItem(id);
4094                         popup->insertItem(new CustomItem(QString("%1 ").arg(nbSel) + type +
4095                                         " (s) ", f), id, 0);
4096                 }
4097         }
4098         return false;
4099 }
4100
4101 //=============================================================================
4102 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
4103  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
4104  */
4105 //=============================================================================
4106 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
4107 {
4108         /* Create or retrieve an object SMESHGUI */
4109         SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
4110
4111         QAD_StudyFrame *activeFrame =
4112                 smeshGUI->myActiveStudy->getActiveStudyFrame();
4113         if (activeFrame->getTypeView() == VIEW_VTK)
4114         {
4115                 // VTK
4116                 SALOMEDS::SObject_var fatherSF =
4117                         smeshGUI->myStudy->FindObjectID(activeFrame->entry());
4118
4119                 SALOME_Selection *Sel =
4120                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
4121                         getSelection());
4122                 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4123
4124 //    for(;It.More();It.Next()) {
4125 //      Handle(SALOME_InteractiveObject) IObject = It.Value();
4126                 Handle(SALOME_InteractiveObject) IObject = theIO;
4127                 if (IObject->hasEntry())
4128                 {
4129                         // Look for the actor in all views
4130                         Standard_Boolean res;
4131                         SMESH_Actor *ac =
4132                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
4133
4134                         // Actor not found at all -> mesh is not computed -> do nothing!!!
4135                         if (!res)
4136                         {
4137                                 /*SMESH::SMESH_Mesh_var aM;
4138                                  * SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
4139                                  * SALOMEDS::SObject_var father = aMorSM->GetFather();
4140                                  * SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
4141                                  * 
4142                                  * // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
4143                                  * if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
4144                                  * continue;
4145                                  * 
4146                                  * SALOMEDS::GenericAttribute_var anAttr;
4147                                  * SALOMEDS::AttributeIOR_var     anIOR;
4148                                  * if ( !aMorSM->_is_nil() ) {
4149                                  * if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
4150                                  * anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4151                                  * aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
4152                                  * }
4153                                  * }
4154                                  * 
4155                                  * if (!aM->_is_nil()) {
4156                                  * smeshGUI->InitActor(aM);
4157                                  * ac = smeshGUI->ReadScript(aM);
4158                                  * }
4159                                  * 
4160                                  * if (ac) {
4161                                  * smeshGUI->DisplayActor( ac, true );
4162                                  * smeshGUI->DisplayEdges( ac ); 
4163                                  * smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
4164                                  * } */
4165 //    continue;
4166                         }
4167                         else
4168                         {                                       // The actor exists in some view
4169                                 // Check whether the actor belongs to the active view
4170                                 VTKViewer_RenderWindowInteractor *rwInter =
4171                                         ((VTKViewer_ViewFrame *) activeFrame->getRightFrame()->
4172                                         getViewFrame())->getRWInteractor();
4173
4174                                 // The actor belongs to inactive view -> create a copy and display it in the active view
4175                                 if (!rwInter->isInViewer(IObject))
4176                                 {
4177                                         if(ac->GetMapper()==NULL)
4178                                         {
4179                                                 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(theIO, res);
4180                                                 ac=smeshGUI->ReadScript(aMesh);
4181                                         }
4182                                         SMESH_Actor *acCopy = SMESH_Actor::New();
4183                                         acCopy->ShallowCopy(ac);
4184                                         ac = acCopy;
4185                                 }
4186                                 smeshGUI->DisplayActor(ac, false);
4187                                 smeshGUI->DisplayEdges(ac);
4188                                 smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
4189                         }
4190                 }
4191 //    }
4192         }
4193         else
4194         {
4195         MESSAGE
4196                         ("BuildPresentation() must not be called while non-VTK view is active")}
4197 }
4198
4199 //=============================================================================
4200 /*!
4201  *
4202  */
4203 //=============================================================================
4204 void SMESHGUI::setOrb()
4205 {
4206         try
4207         {
4208                 ORB_INIT & init = *SINGLETON_ < ORB_INIT >::Instance();
4209                 ASSERT(SINGLETON_ < ORB_INIT >::IsAlreadyExisting());
4210                 _orb = init(0, 0);
4211         } catch(...)
4212         {
4213                 INFOS("internal error : orb not found");
4214                 _orb = 0;
4215         }
4216         ASSERT(!CORBA::is_nil(_orb));
4217 }
4218
4219 //=============================================================================
4220 /*!
4221  *
4222  */
4223 //=============================================================================
4224 SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
4225 {
4226         SMESH_Actor *MeshActor;
4227         if (!aMesh->_is_nil())
4228         {
4229                 Standard_Boolean result;
4230                 MeshActor = FindActor(aMesh, result, false);
4231                 if (result)
4232                 {
4233                         SMESH::log_array_var aSeq = aMesh->GetLog(true);
4234
4235                         if (aSeq->length() == 0)
4236                         {
4237                                 MESSAGE("ReadScript(): log is empty") return MeshActor;
4238                         }
4239
4240                         for (unsigned int ind = 0; ind < aSeq->length(); ind++)
4241                         {
4242                                 switch (aSeq[ind].commandType)
4243                                 {
4244                                 case SMESH::ADD_NODE:
4245                                 {
4246                                         AddNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4247                                                 aSeq[ind].indexes);
4248                                         break;
4249                                 }
4250                                 case SMESH::ADD_EDGE:
4251                                 {
4252                                         //          AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
4253                                         break;
4254                                 }
4255                                 case SMESH::ADD_TRIANGLE:
4256                                 {
4257                                         AddTriangles(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4258                                                 aSeq[ind].indexes);
4259                                         break;
4260                                 }
4261                                 case SMESH::ADD_QUADRANGLE:
4262                                 {
4263                                         AddQuadrangles(MeshActor, aSeq[ind].number,
4264                                                 aSeq[ind].coords, aSeq[ind].indexes);
4265                                         break;
4266                                 }
4267                                 case SMESH::ADD_TETRAHEDRON:
4268                                 {
4269                                         AddTetras(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4270                                                 aSeq[ind].indexes);
4271                                         break;
4272                                 }
4273                                 case SMESH::ADD_PYRAMID:
4274                                 {
4275                                         break;
4276                                 }
4277                                 case SMESH::ADD_PRISM:
4278                                 {
4279                                         break;
4280                                 }
4281                                 case SMESH::ADD_HEXAHEDRON:
4282                                 {
4283                                         AddHexaedres(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4284                                                 aSeq[ind].indexes);
4285                                         break;
4286                                 }
4287                                 case SMESH::REMOVE_NODE:
4288                                 {
4289                                         RemoveNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4290                                                 aSeq[ind].indexes);
4291                                         break;
4292                                 }
4293                                 case SMESH::REMOVE_ELEMENT:
4294                                 {
4295                                         RemoveElements(MeshActor, aSeq[ind].number,
4296                                                 aSeq[ind].coords, aSeq[ind].indexes);
4297                                         break;
4298                                 }
4299                                 }
4300                         }
4301                         return MeshActor;
4302                 }
4303         }
4304         return NULL;
4305 }
4306
4307 //=============================================================================
4308 /*!
4309  *
4310  */
4311 //=============================================================================
4312 void SMESHGUI::Dump(SMESH_Actor * Mactor)
4313 {
4314         vtkUnstructuredGrid *ugrid =
4315                 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
4316         vtkPoints *Pts = ugrid->GetPoints();
4317         int nbPts = Pts->GetNumberOfPoints();
4318         int nbCells = ugrid->GetNumberOfCells();
4319
4320         FILE *In;
4321         int i, j;
4322         In = fopen("/tmp/dumpMesh", "w+");
4323         fprintf(In, "%d %d\n", nbPts, nbCells);
4324         for (int i = 0; i < nbPts; i++)
4325         {
4326                 float *p = ugrid->GetPoint(i);
4327                 fprintf(In, "%d %e %e %e\n", i, p[0], p[1], p[2]);
4328         }
4329
4330         for (int i = 0; i < nbCells; i++)
4331         {
4332                 fprintf(In, "%d %d", i, ugrid->GetCell(i)->GetCellType());
4333                 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
4334                 for (j = 0; j < Id->GetNumberOfIds(); j++)
4335                 {
4336                         fprintf(In, " %d", Id->GetId(j));
4337                 }
4338                 fprintf(In, "\n");
4339         }
4340         fclose(In);
4341 }
4342
4343 //=============================================================================
4344 /*!
4345  *
4346  */
4347 //=============================================================================
4348 void SMESHGUI::AddNodes(SMESH_Actor * Mactor, int number,
4349         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4350 {
4351         QApplication::setOverrideCursor(Qt::waitCursor);
4352         if (Mactor->GetMapper() == NULL)
4353         {
4354                 vtkPoints *Pts = vtkPoints::New();
4355                 SMESH_Grid *ugrid = SMESH_Grid::New();
4356                 ugrid->Allocate();
4357
4358                 int i = 1;
4359                 int j = 1;
4360                 while (i <= number)
4361                 {
4362                         int idVTK =
4363                                 Pts->InsertNextPoint(coords[j - 1], coords[j], coords[j + 1]);
4364                         //Mactor->AddNode( indexes[i-1], idVTK );
4365                         ugrid->AddNode(indexes[i - 1], idVTK);
4366                         i++;
4367                         j = j + 3;
4368                 }
4369                 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4370                 ugrid->SetPoints(Pts);
4371                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4372                 PtsMapper->SetInput(ugrid);
4373                 Mactor->DataSource = PtsMapper->GetInput();
4374                 Mactor->SetMapper(PtsMapper);
4375         }
4376         else
4377         {
4378                 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4379                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4380                 int i = 1;
4381                 int j = 1;
4382                 while (i <= number)
4383                 {
4384                         int idVTK =
4385                                 ugrid->GetPoints()->InsertNextPoint(coords[j - 1], coords[j],
4386                                 coords[j + 1]);
4387                         ugrid->AddNode(indexes[i - 1], idVTK);
4388                         i++;
4389                         j = j + 3;
4390                 }
4391                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4392                 PtsMapper->SetInput(ugrid);
4393                 Mactor->DataSource = PtsMapper->GetInput();
4394                 Mactor->SetMapper(PtsMapper);
4395         }
4396         QApplication::restoreOverrideCursor();
4397 }
4398
4399 //=============================================================================
4400 /*!
4401  *
4402  */
4403 //=============================================================================
4404 void SMESHGUI::AddNode(SMESH_Actor * Mactor, int idnode, float x, float y,
4405         float z)
4406 {
4407         QApplication::setOverrideCursor(Qt::waitCursor);
4408         MESSAGE("SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" <<
4409                 z) if (Mactor->GetMapper() == NULL)
4410         {
4411                 vtkPoints *Pts = vtkPoints::New();
4412                 int idVTK = Pts->InsertNextPoint(x, y, z);
4413                 //Mactor->AddNode( idnode, idVTK );
4414                 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4415                 SMESH_Grid *ugrid = SMESH_Grid::New();
4416                 ugrid->Allocate();
4417                 ugrid->AddNode(idnode, idVTK);
4418                 ugrid->SetPoints(Pts);
4419                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4420                 PtsMapper->SetInput(ugrid);
4421                 Mactor->DataSource = PtsMapper->GetInput();
4422                 Mactor->SetMapper(PtsMapper);
4423         }
4424         else
4425         {
4426                 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4427                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4428                 int idVTK = ugrid->GetPoints()->InsertNextPoint(x, y, z);
4429                 //Mactor->AddNode( idnode, idVTK );
4430                 ugrid->AddNode(idnode, idVTK);
4431                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4432                 PtsMapper->SetInput(ugrid);
4433                 Mactor->DataSource = PtsMapper->GetInput();
4434                 Mactor->SetMapper(PtsMapper);
4435         }
4436         QApplication::restoreOverrideCursor();
4437 }
4438
4439 //=============================================================================
4440 /*!
4441  *
4442  */
4443 //=============================================================================
4444 void SMESHGUI::RemoveNode(SMESH_Actor * Mactor, int idnode)
4445 {
4446         MESSAGE(" OLD RemoveNode method ")
4447 //   int id = Mactor->GetIdVTKNode( idnode );
4448 //    MESSAGE ( " RemoveNode id VTK " << id )
4449 //    if ( Mactor->GetMapper() != NULL ) {
4450 //      vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4451 //      vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4452 //      vtkPoints *Pts = ugrid->GetPoints();
4453 //      vtkPoints *newPts = vtkPoints::New();
4454 //      int nbPts = Pts->GetNumberOfPoints();
4455 //      bool findPt = false;
4456 //      for ( int i = 0; i < nbPts; i++ ) {
4457 //        if ( id != i ) {
4458 //      if ( !findPt)
4459 //        newPts->InsertPoint(i, Pts->GetPoint(i) );
4460 //      else
4461 //        newPts->InsertPoint(i-1, Pts->GetPoint(i) );
4462 //        } else {
4463 //      findPt = true;
4464 //      Mactor->RemoveNode( idnode );
4465 //        }
4466 //      }
4467 //      newUgrid->SetPoints(newPts);
4468 //      int nbCells = ugrid->GetNumberOfCells();
4469 //      for ( int i = 0; i < nbCells; i++ ) {
4470 //        vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4471 //        vtkIdList *newIds = vtkIdList::New();
4472 //        int nbIds = Ids->GetNumberOfIds();
4473 //        newIds->SetNumberOfIds(nbIds);
4474 //        for ( int j = 0; j < nbIds; j++ ) {
4475 //      int theid = Ids->GetId(j);
4476 //      if ( theid > id ) {
4477 //        newIds->SetId( j, theid-1 );
4478 //      } else
4479 //        newIds->SetId( j, theid );
4480 //        }
4481 //        int idSMDSel = Mactor->GetIdSMESHDSElement( i );
4482 //        Mactor->RemoveElement( idSMDSel, false );
4483 //        int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
4484 //        Mactor->AddElement( idSMDSel, idVTKel );
4485 //      }
4486 //      vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4487 //      Mapper->SetInput( newUgrid );
4488 //      Mactor->DataSource = Mapper->GetInput();
4489 //      Mactor->SetMapper(Mapper);
4490 //      UpdateView();
4491 //    }
4492 }
4493
4494 //=============================================================================
4495 /*!
4496  *
4497  */
4498 //=============================================================================
4499 void SMESHGUI::RemoveNodes(SMESH_Actor * Mactor, int number,
4500         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4501 {
4502         QApplication::setOverrideCursor(Qt::waitCursor);
4503         int i = 1;
4504         while (i <= number)
4505         {
4506                 Mactor->RemoveNode(indexes[i - 1]);
4507                 i++;
4508         }
4509
4510         TColStd_DataMapOfIntegerInteger newMapVTKNodes;
4511         TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
4512         TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
4513
4514         if (Mactor->GetMapper() != NULL)
4515         {
4516                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4517                 SMESH_Grid *newUgrid = SMESH_Grid::New();
4518                 newUgrid->CopyMaps(ugrid);
4519
4520                 vtkPoints *Pts = ugrid->GetPoints();
4521                 vtkPoints *newPts = vtkPoints::New();
4522                 int nbPts = Pts->GetNumberOfPoints();
4523                 int j = 0;
4524                 for (int i = 0; i < nbPts; i++)
4525                 {
4526                         int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
4527                         if (idSMESHDSNode != -1)
4528                         {
4529                                 newPts->InsertPoint(j, Pts->GetPoint(i));
4530
4531                                 newMapVTKNodes.Bind(j, idSMESHDSNode);
4532                                 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
4533
4534                                 MapOldNodesToNewNodes.Bind(i, j);
4535                                 j++;
4536                         }
4537                 }
4538
4539                 newUgrid->SetIdsVTKNode(newMapVTKNodes);
4540                 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
4541                 newUgrid->SetPoints(newPts);
4542
4543                 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4544                 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4545
4546                 int nbCells = ugrid->GetNumberOfCells();
4547                 for (int i = 0; i < nbCells; i++)
4548                 {
4549                         vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4550                         vtkIdList *newIds = vtkIdList::New();
4551                         int nbIds = Ids->GetNumberOfIds();
4552                         newIds->SetNumberOfIds(nbIds);
4553                         bool isGood = true;
4554                         for (int j = 0; j < nbIds; j++)
4555                         {
4556                                 int theid = Ids->GetId(j);
4557                                 if (MapOldNodesToNewNodes.IsBound(theid))
4558                                 {
4559                                         newIds->SetId(j, MapOldNodesToNewNodes.Find(theid));
4560                                 }
4561                                 else
4562                                 {
4563                                         isGood = false;
4564                                         break;
4565                                 }
4566                         }
4567
4568                         // Filtering out cells based on non-existing nodes
4569                         if (isGood)
4570                         {
4571                                 int idSMDSel = Mactor->GetIdSMESHDSElement(i);
4572                                 int idVTKel =
4573                                         newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4574                                         newIds);
4575
4576                                 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
4577                                 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
4578                         }
4579                 }
4580
4581                 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4582                 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4583
4584                 // Copy new data to the old DatSource: keep the single DataSource for all actors
4585                 ugrid->DeepCopy(newUgrid);
4586
4587                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4588                 Mapper->SetInput(ugrid);
4589                 Mactor->SetMapper(Mapper);
4590
4591                 // Commented to avoid multiple viewer updates when called by ReadScript()
4592                 //UpdateView();
4593
4594         }
4595         QApplication::restoreOverrideCursor();
4596 }
4597
4598 //=============================================================================
4599 /*!
4600  *
4601  */
4602 //=============================================================================
4603 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh,
4604         const TColStd_MapOfInteger & MapIndex)
4605 {
4606         QApplication::setOverrideCursor(Qt::waitCursor);
4607         Standard_Boolean result;
4608         SMESH_Actor *ac = FindActor(aMesh, result, true);
4609         if (result)
4610         {
4611                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4612                 anArrayOfIdeces->length(MapIndex.Extent());
4613                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4614                 int i = 0;
4615                 for (; ite.More(); ite.Next())
4616                 {
4617                         //      MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
4618                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
4619                         i++;
4620                 }
4621                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4622                 aMeshEditor->RemoveNodes(anArrayOfIdeces);
4623
4624         }
4625         if (myAutomaticUpdate)
4626         {
4627                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4628                 if (Mesh != NULL)
4629                 {
4630                         smeshGUI->DisplayActor(Mesh);
4631                         smeshGUI->DisplayEdges(Mesh);
4632                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4633                         AddActorInSelection(Mesh);
4634                 }
4635         }
4636         QApplication::restoreOverrideCursor();
4637 }
4638
4639 //=============================================================================
4640 /*!
4641  *
4642  */
4643 //=============================================================================
4644 void SMESHGUI::RemoveElement(SMESH_Actor * Mactor, int idelement)
4645 {
4646         MESSAGE(" OLD RemoveElement method ")
4647 //    int id = Mactor->GetIdVTKElement( idelement );
4648 //    MESSAGE ( " RemoveElement id VTK : " << id )
4649 //    if ( Mactor->GetMapper() != NULL ) {
4650 //      vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4651 //      vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4652 //      int nbCells = ugrid->GetNumberOfCells();
4653 //      for ( int i = 0; i < nbCells; i++ ) {
4654 //        if ( id != i ) {
4655 //      newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), 
4656 //                    ugrid->GetCell(i)->GetPointIds() );
4657 //        } else
4658 //      Mactor->RemoveElement( idelement );
4659 //      }
4660 //      newUgrid->SetPoints(ugrid->GetPoints());
4661 //      vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4662 //      Mapper->SetInput( newUgrid );
4663 //      Mactor->DataSource = Mapper->GetInput();
4664 //      Mactor->SetMapper(Mapper);
4665 //      UpdateView();
4666 //    }
4667 }
4668
4669 //=============================================================================
4670 /*!
4671  *
4672  */
4673 //=============================================================================
4674 void SMESHGUI::RemoveElements(SMESH_Actor * Mactor, int number,
4675         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4676 {
4677         QApplication::setOverrideCursor(Qt::waitCursor);
4678         int i = 1;
4679         while (i <= number)
4680         {
4681                 Mactor->RemoveElement(indexes[i - 1]);
4682                 i++;
4683         }
4684         TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4685         TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4686
4687         if (Mactor->GetMapper() != NULL)
4688         {
4689                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4690                 SMESH_Grid *newUgrid = SMESH_Grid::New();
4691                 newUgrid->CopyMaps(ugrid);
4692
4693                 int nbCells = ugrid->GetNumberOfCells();
4694                 for (int i = 0; i < nbCells; i++)
4695                 {
4696                         int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
4697                         if (idSMESHDSElement != -1)
4698                         {
4699                                 int newId =
4700                                         newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4701                                         ugrid->GetCell(i)->GetPointIds());
4702                                 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
4703                                 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
4704                         }
4705                 }
4706
4707                 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4708                 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4709
4710                 newUgrid->SetPoints(ugrid->GetPoints());
4711
4712                 // Copy new data to the old DatSource: keep the single DataSource for all actors
4713                 ugrid->DeepCopy(newUgrid);
4714
4715                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4716                 Mapper->SetInput(ugrid);
4717                 Mactor->SetMapper(Mapper);
4718
4719                 // Commented to avoid multiple viewer updates when called by ReadScript()
4720                 //UpdateView();
4721         }
4722         QApplication::restoreOverrideCursor();
4723 }
4724
4725 //=============================================================================
4726 /*!
4727  *
4728  */
4729 //=============================================================================
4730 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh,
4731         const TColStd_MapOfInteger & MapIndex)
4732 {
4733         QApplication::setOverrideCursor(Qt::waitCursor);
4734         Standard_Boolean result;
4735         SMESH_Actor *ac = FindActor(aMesh, result, true);
4736         if (result)
4737         {
4738                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4739                 anArrayOfIdeces->length(MapIndex.Extent());
4740                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4741                 int i = 0;
4742                 for (; ite.More(); ite.Next())
4743                 {
4744                         //      MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
4745                         anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
4746                         i++;
4747                 }
4748
4749                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4750                 aMeshEditor->RemoveElements(anArrayOfIdeces);
4751         }
4752
4753         if (myAutomaticUpdate)
4754         {
4755                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4756                 if (Mesh != NULL)
4757                 {
4758                         smeshGUI->DisplayActor(Mesh);
4759                         smeshGUI->DisplayEdges(Mesh);
4760                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4761                         AddActorInSelection(Mesh);
4762 #ifdef TRACE
4763                         Dump(Mesh);
4764 #endif
4765                 }
4766         }
4767         QApplication::restoreOverrideCursor();
4768 }
4769
4770 //=============================================================================
4771 /*!
4772  *
4773  */
4774 //=============================================================================
4775 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh,
4776         const TColStd_MapOfInteger & MapIndex)
4777 {
4778         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4779                 return;
4780
4781         vtkRenderer *theRenderer =
4782                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4783                 getRightFrame()->getViewFrame())->getRenderer();
4784         Standard_Boolean result;
4785         SMESH_Actor *ac = FindActor(aMesh, result, true);
4786         if (result)
4787         {
4788                 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4789                 SMESH_Grid *UGrid = SMESH_Grid::New();
4790                 SMESH_Grid *oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
4791                 UGrid->CopyMaps(oldGrid);
4792
4793                 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4794                 gf->SetInput(ac->DataSource);
4795
4796                 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4797                 Mapper->SetInput(gf->GetOutput());
4798                 Mapper->Update();
4799
4800                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4801                 for (; ite.More(); ite.Next())
4802                 {
4803                         Mapper->GetInput()->ReverseCell(ite.Key());
4804                 }
4805
4806                 UGrid->SetPoints(Mapper->GetInput()->GetPoints());
4807                 int nbCells = Mapper->GetInput()->GetNumberOfCells();
4808                 for (int i = 0; i < nbCells; i++)
4809                 {
4810                         UGrid->InsertNextCell(Mapper->GetInput()->GetCellType(i),
4811                                 Mapper->GetInput()->GetCell(i)->GetPointIds());
4812                 }
4813
4814                 // Copy new data to the old DatSource: keep the single DataSource for all actors
4815                 oldGrid->DeepCopy(UGrid);
4816
4817                 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4818                 //NewMapper->SetInput( UGrid );
4819                 NewMapper->SetInput(oldGrid);
4820                 NewMapper->Update();
4821
4822                 //ac->DataSource = NewMapper->GetInput();
4823                 ac->SetMapper(NewMapper);
4824         }
4825         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4826         renWin->Render();
4827         QApplication::restoreOverrideCursor();
4828 }
4829
4830 //=============================================================================
4831 /*!
4832  *
4833  */
4834 //=============================================================================
4835 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh,
4836         const TColStd_MapOfInteger & MapIndex)
4837 {
4838         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4839                 return;
4840
4841         QApplication::setOverrideCursor(Qt::waitCursor);
4842         vtkRenderer *theRenderer =
4843                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4844                 getRightFrame()->getViewFrame())->getRenderer();
4845         Standard_Boolean result;
4846
4847         SMESH_Actor *ac = FindActor(aMesh, result, true);
4848         if (result)
4849         {
4850                 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4851                 SMESH_Grid *UGrid = SMESH_Grid::New();
4852                 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4853                 gf->SetInput(ac->DataSource);
4854
4855                 vtkExtractEdges *edges = vtkExtractEdges::New();
4856                 edges->SetInput(ac->DataSource);
4857
4858                 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4859                 Mapper->SetInput(edges->GetOutput());
4860                 Mapper->Update();
4861
4862                 int nb = Mapper->GetInput()->GetNumberOfCells();
4863                 //MESSAGE ( "nb : " << nb )
4864
4865                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4866                 for (; ite.More(); ite.Next())
4867                 {
4868                         vtkCell *StartEdge = Mapper->GetInput()->GetCell(ite.Key());
4869                         //MESSAGE( "DCQ : Edge Id = " << ite.Key())
4870                         int CellType = StartEdge->GetCellType();
4871                         //MESSAGE( "DCQ : Cell Type = " << CellType)
4872                         int nbPoints = StartEdge->GetNumberOfPoints();
4873
4874                         //MESSAGE( "DCQ : Nb Point = " << nbPoints)
4875                         if (nbPoints == 2)
4876                         {
4877                                 vtkUnstructuredGrid *StartUGrid =
4878                                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
4879
4880                                 vtkIdList *IdCells = vtkIdList::New();
4881                                 vtkIdList *IdPoints = StartEdge->GetPointIds();
4882                                 float p1[3];
4883                                 float p2[3];
4884
4885                                 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),
4886                                         p1);
4887                                 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),
4888                                         p2);
4889
4890                                 int idp1 = StartUGrid->FindPoint(p1);
4891                                 int idp2 = StartUGrid->FindPoint(p2);
4892
4893                                 StartUGrid->GetPointCells(idp1, IdCells);
4894
4895                                 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4896                                 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4897
4898                                 //MESSAGE ( " pt 0 : " << idp1 )
4899                                 //MESSAGE ( " pt 1 : " << idp2 )
4900
4901                                 vtkIdList *IdPts = vtkIdList::New();
4902                                 if (IdCells->GetNumberOfIds() >= 2)
4903                                 {
4904                                         int nbCells = IdCells->GetNumberOfIds();
4905                                         //MESSAGE ( " nbCells : " << nbCells )
4906                                         for (int j = 0; j < nbCells; j++)
4907                                         {
4908                                                 StartUGrid->GetCellPoints(IdCells->GetId(j), IdPts);
4909                                                 if (IdPts->IsId(idp2) == -1)
4910                                                 {
4911                                                         IdCells->DeleteId(IdCells->GetId(j));
4912                                                 }
4913                                         }
4914
4915                                         //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4916
4917                                         vtkIdList *IdPts0 = vtkIdList::New();
4918                                         vtkIdList *IdPts1 = vtkIdList::New();
4919
4920                                         if (IdCells->GetNumberOfIds() == 2)
4921                                         {
4922                                                 StartUGrid->GetCellPoints(IdCells->GetId(0), IdPts0);
4923                                                 StartUGrid->GetCellPoints(IdCells->GetId(1), IdPts1);
4924
4925                                                 //Create new faces
4926                                                 TColStd_MapOfInteger EndMapIndex;
4927                                                 for (int j = 0; j < 3; j++)
4928                                                 {
4929                                                         if (IdPts0->GetId(j) != idp1 &&
4930                                                                 IdPts0->GetId(j) != idp2)
4931                                                         {
4932                                                                 EndMapIndex.Add(IdPts0->GetId(j));
4933                                                         }
4934                                                         if (IdPts1->GetId(j) != idp1 &&
4935                                                                 IdPts1->GetId(j) != idp2)
4936                                                         {
4937                                                                 EndMapIndex.Add(IdPts1->GetId(j));
4938                                                         }
4939                                                 }
4940
4941                                                 bool MyAU = myAutomaticUpdate;
4942                                                 myAutomaticUpdate = false;
4943
4944                                                 EndMapIndex.Add(idp1);
4945                                                 TColStd_MapIteratorOfMapOfInteger ite1(EndMapIndex);
4946                                                 int i = 1;
4947                                                 while (ite1.More())
4948                                                 {
4949                                                         if (ite1.Key() == idp1)
4950                                                                 break;
4951                                                         i++;
4952                                                         ite1.Next();
4953                                                 }
4954                                                 bool reverse1 = (i == 2);
4955                                                 this->AddFace(aMesh, EndMapIndex, reverse1);
4956
4957                                                 EndMapIndex.Remove(idp1);
4958                                                 EndMapIndex.Add(idp2);
4959                                                 TColStd_MapIteratorOfMapOfInteger ite2(EndMapIndex);
4960                                                 i = 1;
4961                                                 while (ite2.More())
4962                                                 {
4963                                                         if (ite2.Key() == idp2)
4964                                                                 break;
4965                                                         i++;
4966                                                         ite2.Next();
4967                                                 }
4968                                                 bool reverse2 = (i == 2);
4969                                                 this->AddFace(aMesh, EndMapIndex,
4970                                                         !(reverse1 == reverse2));
4971
4972                                                 myAutomaticUpdate = MyAU;
4973                                                 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4974                                                 Mapper->Update();
4975                                                 //Remove old faces
4976                                                 TColStd_MapOfInteger StartMapIndex;
4977                                                 StartMapIndex.Add(IdCells->GetId(0));
4978                                                 StartMapIndex.Add(IdCells->GetId(1));
4979                                                 this->RemoveElements(aMesh, StartMapIndex);
4980
4981                                                 Mapper->Update();
4982                                         }
4983                                 }
4984                         }
4985                 }
4986
4987                 //      UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4988                 //      int nbCells = Mapper->GetInput()->GetNumberOfCells();
4989                 //      for ( int i = 0; i < nbCells; i++ ) {
4990                 //        UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4991                 //      }
4992
4993                 //      vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4994                 //      NewMapper->SetInput( UGrid );
4995                 //      NewMapper->Update();
4996
4997                 //      ac->DataSource = NewMapper->GetInput();
4998                 //      ac->SetMapper( NewMapper );
4999         }
5000         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5001         renWin->Render();
5002         QApplication::restoreOverrideCursor();
5003 }
5004
5005 //=============================================================================
5006 /*!
5007  *
5008  */
5009 //=============================================================================
5010 void SMESHGUI::AddEdges(SMESH_Actor * Mactor, int number,
5011         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5012 {
5013         QApplication::setOverrideCursor(Qt::waitCursor);
5014         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5015         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5016         int i = 1;
5017         int j = 1;
5018         while (i <= number)
5019         {
5020                 vtkIdList *Ids = vtkIdList::New();
5021                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5022                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5023                 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
5024                 Mactor->AddElement(indexes[j - 1], id);
5025                 i++;
5026                 j = j + 3;
5027         }
5028         vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
5029         EdgeMapper->SetInput(ugrid);
5030         Mactor->DataSource = EdgeMapper->GetInput();
5031         Mactor->SetMapper(EdgeMapper);
5032         QApplication::restoreOverrideCursor();
5033 }
5034
5035 //=============================================================================
5036 /*!
5037  *
5038  */
5039 //=============================================================================
5040 void SMESHGUI::AddEdge(SMESH_Actor * Mactor, int idedge, int idnode1,
5041         int idnode2)
5042 {
5043         QApplication::setOverrideCursor(Qt::waitCursor);
5044         MESSAGE("SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" <<
5045                 idnode2) vtkIdList *Ids = vtkIdList::New();
5046         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5047         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5048
5049         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5050         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5051         int id = ugrid->InsertNextCell(VTK_LINE, Ids);
5052         Mactor->AddElement(idedge, id);
5053
5054         MESSAGE(" Edge VTK id " << id)
5055                 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
5056         EdgeMapper->SetInput(ugrid);
5057         Mactor->DataSource = EdgeMapper->GetInput();
5058         Mactor->SetMapper(EdgeMapper);
5059         QApplication::restoreOverrideCursor();
5060 }
5061
5062 //=============================================================================
5063 /*!
5064  *
5065  */
5066 //=============================================================================
5067 void SMESHGUI::AddTriangles(SMESH_Actor * Mactor, int number,
5068         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5069 {
5070         QApplication::setOverrideCursor(Qt::waitCursor);
5071         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5072         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5073         int i = 1;
5074         int j = 1;
5075         while (i <= number)
5076         {
5077                 vtkIdList *Ids = vtkIdList::New();
5078                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5079                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5080                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5081                 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
5082                 Mactor->AddElement(indexes[j - 1], id);
5083                 i++;
5084                 j = j + 4;
5085         }
5086         vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
5087         TriMapper->SetInput(ugrid);
5088         Mactor->DataSource = TriMapper->GetInput();
5089         Mactor->SetMapper(TriMapper);
5090         QApplication::restoreOverrideCursor();
5091 }
5092 void SMESHGUI::AddTriangle(SMESH_Actor * Mactor, int idtri, int idnode1,
5093         int idnode2, int idnode3)
5094 {
5095         QApplication::setOverrideCursor(Qt::waitCursor);
5096         vtkIdList *Ids = vtkIdList::New();
5097         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5098         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5099         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5100
5101         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5102         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5103         int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
5104         Mactor->AddElement(idtri, id);
5105
5106         vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
5107         TriMapper->SetInput(ugrid);
5108         Mactor->DataSource = TriMapper->GetInput();
5109         Mactor->SetMapper(TriMapper);
5110         QApplication::restoreOverrideCursor();
5111 }
5112
5113 //=============================================================================
5114 /*!
5115  *
5116  */
5117 //=============================================================================
5118 void SMESHGUI::AddQuadrangles(SMESH_Actor * Mactor, int number,
5119         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5120 {
5121         QApplication::setOverrideCursor(Qt::waitCursor);
5122         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5123         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5124         int i = 1;
5125         int j = 1;
5126         while (i <= number)
5127         {
5128                 vtkIdList *Ids = vtkIdList::New();
5129                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5130                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5131                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5132                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5133                 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5134                 Mactor->AddElement(indexes[j - 1], id);
5135                 i++;
5136                 j = j + 5;
5137         }
5138         vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5139         QuadMapper->SetInput(ugrid);
5140         Mactor->DataSource = QuadMapper->GetInput();
5141         Mactor->SetMapper(QuadMapper);
5142         QApplication::restoreOverrideCursor();
5143 }
5144
5145 //=============================================================================
5146 /*!
5147  *
5148  */
5149 //=============================================================================
5150 void SMESHGUI::AddQuadrangle(SMESH_Actor * Mactor, int idquad, int idnode1,
5151         int idnode2, int idnode3, int idnode4)
5152 {
5153         QApplication::setOverrideCursor(Qt::waitCursor);
5154         vtkIdList *Ids = vtkIdList::New();
5155         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5156         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5157         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5158         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5159
5160         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5161         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5162         int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5163         Mactor->AddElement(idquad, id);
5164
5165         vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5166         QuadMapper->SetInput(ugrid);
5167         Mactor->DataSource = QuadMapper->GetInput();
5168         Mactor->SetMapper(QuadMapper);
5169         QApplication::restoreOverrideCursor();
5170 }
5171
5172 //=============================================================================
5173 /*!
5174  *
5175  */
5176 //=============================================================================
5177 void SMESHGUI::AddTetras(SMESH_Actor * Mactor, int number,
5178         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5179 {
5180         QApplication::setOverrideCursor(Qt::waitCursor);
5181         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5182         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5183         int i = 1;
5184         int j = 1;
5185         while (i <= number)
5186         {
5187                 vtkIdList *Ids = vtkIdList::New();
5188                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5189                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5190                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5191                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5192                 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5193                 Mactor->AddElement(indexes[j - 1], id);
5194                 i++;
5195                 j = j + 5;
5196         }
5197         vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5198         TetraMapper->SetInput(ugrid);
5199         Mactor->DataSource = TetraMapper->GetInput();
5200         Mactor->SetMapper(TetraMapper);
5201         QApplication::restoreOverrideCursor();
5202 }
5203
5204 //=============================================================================
5205 /*!
5206  *
5207  */
5208 //=============================================================================
5209 void SMESHGUI::AddTetra(SMESH_Actor * Mactor, int idtetra, int idnode1,
5210         int idnode2, int idnode3, int idnode4)
5211 {
5212         QApplication::setOverrideCursor(Qt::waitCursor);
5213         MESSAGE("SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" <<
5214                 idnode2 << ";" << idnode3 << ";" << idnode4) vtkIdList *Ids =
5215                 vtkIdList::New();
5216         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5217         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5218         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5219         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5220
5221         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5222         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5223         int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5224         Mactor->AddElement(idtetra, id);
5225
5226         MESSAGE(" Tetra VTK id " << id)
5227                 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5228         TetraMapper->SetInput(ugrid);
5229         Mactor->DataSource = TetraMapper->GetInput();
5230         Mactor->SetMapper(TetraMapper);
5231         QApplication::restoreOverrideCursor();
5232 }
5233
5234 //=============================================================================
5235 /*!
5236  *
5237  */
5238 //=============================================================================
5239 void SMESHGUI::AddHexaedres(SMESH_Actor * Mactor, int number,
5240         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5241 {
5242         QApplication::setOverrideCursor(Qt::waitCursor);
5243         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5244         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5245         int i = 1;
5246         int j = 1;
5247         while (i <= number)
5248         {
5249                 vtkIdList *Ids = vtkIdList::New();
5250                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5251                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5252                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5253                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5254                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 4]));
5255                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 5]));
5256                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 6]));
5257                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 7]));
5258                 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5259                 Mactor->AddElement(indexes[j - 1], id);
5260                 i++;
5261                 j = j + 9;
5262         }
5263         vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5264         HexaMapper->SetInput(ugrid);
5265         Mactor->DataSource = HexaMapper->GetInput();
5266         Mactor->SetMapper(HexaMapper);
5267         QApplication::restoreOverrideCursor();
5268 }
5269
5270 //=============================================================================
5271 /*!
5272  *
5273  */
5274 //=============================================================================
5275 void SMESHGUI::AddHexaedre(SMESH_Actor * Mactor, int idhexa, int idnode1,
5276         int idnode2, int idnode3, int idnode4, int idnode5, int idnode6,
5277         int idnode7, int idnode8)
5278 {
5279         QApplication::setOverrideCursor(Qt::waitCursor);
5280         MESSAGE("SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" <<
5281                 idnode2 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" <<
5282                 idnode6 << ";" << idnode7 << ";" << idnode8) vtkIdList *Ids =
5283                 vtkIdList::New();
5284         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5285         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5286         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5287         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5288         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode5));
5289         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode6));
5290         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode7));
5291         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode8));
5292
5293         //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5294         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5295         int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5296         Mactor->AddElement(idhexa, id);
5297
5298         MESSAGE(" Hexa VTK id " << id)
5299                 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5300         HexaMapper->SetInput(ugrid);
5301         Mactor->DataSource = HexaMapper->GetInput();
5302         Mactor->SetMapper(HexaMapper);
5303         QApplication::restoreOverrideCursor();
5304 }
5305
5306 //=====================================================================================
5307 // EXPORTED METHODS
5308 //=====================================================================================
5309 extern "C"
5310 {
5311         bool OnGUIEvent(int theCommandID, QAD_Desktop * parent)
5312         {
5313                 return SMESHGUI::OnGUIEvent(theCommandID, parent);
5314         }
5315
5316         bool OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
5317                 QAD_StudyFrame * studyFrame)
5318         {
5319                 return SMESHGUI::OnKeyPress(pe, parent, studyFrame);
5320         }
5321
5322         bool OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
5323                 QAD_StudyFrame * studyFrame)
5324         {
5325                 return SMESHGUI::OnMousePress(pe, parent, studyFrame);
5326         }
5327
5328         bool OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
5329                 QAD_StudyFrame * studyFrame)
5330         {
5331                 return SMESHGUI::OnMouseMove(pe, parent, studyFrame);
5332         }
5333
5334         bool SetSettings(QAD_Desktop * parent)
5335         {
5336                 return SMESHGUI::SetSettings(parent);
5337         }
5338
5339         bool customPopup(QAD_Desktop * parent, QPopupMenu * popup,
5340                 const QString & theContext, const QString & theParent,
5341                 const QString & theObject)
5342         {
5343                 return SMESHGUI::CustomPopup(parent, popup, theContext, theParent,
5344                         theObject);
5345         }
5346
5347         void definePopup(QString & theContext, QString & theParent,
5348                 QString & theObject)
5349         {
5350                 SMESHGUI::DefinePopup(theContext, theParent, theObject);
5351         }
5352
5353         bool activeStudyChanged(QAD_Desktop * parent)
5354         {
5355                 SMESHGUI::activeStudyChanged(parent);
5356         }
5357
5358         void buildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
5359         {
5360                 SMESHGUI::BuildPresentation(theIO);
5361         }
5362
5363         void supportedViewType(int *buffer, int bufferSize)
5364         {
5365                 if (!buffer || !bufferSize)
5366                         return;
5367                 buffer[0] = (int)VIEW_VTK;
5368         }
5369
5370 }
5371
5372 //=============================================================================
5373 /*!
5374  *
5375  */
5376 //=============================================================================
5377 void SMESHGUI::ViewNodes()
5378 {
5379         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5380                 return;
5381
5382         EraseSimulationActors();
5383         mySimulationActors = vtkActorCollection::New();
5384         vtkRenderer *theRenderer =
5385                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5386                 getRightFrame()->getViewFrame())->getRenderer();
5387         vtkActorCollection *theActors = theRenderer->GetActors();
5388         theActors->InitTraversal();
5389         vtkActor *ac = theActors->GetNextActor();
5390         while (!(ac == NULL))
5391         {
5392                 if (ac->IsA("SMESH_Actor"))
5393                 {
5394                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
5395                         if (anActor->GetVisibility() == 1)
5396                         {
5397                                 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5398                                 gf->SetInput(anActor->DataSource);
5399                                 vtkMaskPoints *verts = vtkMaskPoints::New();
5400                                 verts->SetInput(gf->GetOutput());
5401                                 verts->GenerateVerticesOn();
5402                                 verts->SetOnRatio(1);
5403
5404                                 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
5405                                 vertMapper->SetInput(verts->GetOutput());
5406                                 vertMapper->ScalarVisibilityOff();
5407
5408                                 vtkActor *vertActor = vtkActor::New();
5409                                 vertActor->SetMapper(vertMapper);
5410
5411                                 float r, g, b;
5412                                 anActor->GetNodeColor(r, g, b);
5413                                 vertActor->GetProperty()->SetColor(r, g, b);
5414
5415                                 vertActor->GetProperty()->SetPointSize(anActor->GetNodeSize());
5416
5417                                 vertActor->PickableOff();
5418
5419                                 mySimulationActors->AddItem(vertActor);
5420                                 theRenderer->AddActor(vertActor);
5421                         }
5422                 }
5423                 ac = theActors->GetNextActor();
5424         }
5425
5426         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5427         renWin->Render();
5428 }
5429
5430 //=============================================================================
5431 /*!
5432  *
5433  */
5434 //=============================================================================
5435 void SMESHGUI::Control(int theCommandID)
5436 {
5437         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5438                 return;
5439
5440         QApplication::setOverrideCursor(Qt::waitCursor);
5441         DisplayScalarBar(false);
5442
5443         vtkDoubleArray *scalars = vtkDoubleArray::New();
5444         scalars->SetNumberOfComponents(1);
5445
5446         vtkDataSetMapper *meshMapper = 0;
5447         SALOME_Selection *Sel =
5448                 SALOME_Selection::Selection(myActiveStudy->getSelection());
5449         int nbSel = Sel->IObjectCount();
5450         Standard_Boolean result;
5451         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
5452         SMESH_Actor *MeshActor =
5453                 FindActorByEntry(IObject->getEntry(), result, true);
5454
5455         // Mesh may be not updated after Compute
5456         if (!MeshActor->DataSource || !MeshActor->GetMapper())
5457         {
5458                 QApplication::restoreOverrideCursor();
5459                 return;
5460         }
5461
5462         vtkDataSet *aDataSet = MeshActor->DataSource;
5463         typedef double (*TScalarFun) (vtkCell * theCell);
5464         TScalarFun aScalarFun;
5465         if (result)
5466         {
5467                 QString type;
5468                 switch (theCommandID)
5469                 {
5470                 case 6001:
5471                 {
5472                         type = tr("SMESH_CONTROL_LENGTH_EDGES");
5473                         aDataSet = MeshActor->EdgeDevice->GetMapper()->GetInput();
5474                         aScalarFun = &(SMESHGUI_ComputeScalarValue::LengthEdges);
5475                         MESSAGE(" init minimum length " << aDataSet->GetNumberOfCells());
5476                         if (MeshActor->getDisplayMode() != 0)
5477                                 ChangeRepresentation(MeshActor, 1);     // limitation; in Wireframe, colored edges are not visible
5478                         break;
5479                 }
5480                 case 6011:
5481                 {
5482                         type = tr("SMESH_CONTROL_AREA_ELEMENTS");
5483                         aScalarFun = &(SMESHGUI_ComputeScalarValue::AreaElements);
5484                         if (MeshActor->getDisplayMode() != 1)
5485                                 ChangeRepresentation(MeshActor, 1);
5486                         break;
5487                 }
5488                 case 6012:
5489                 {
5490                         type = tr("SMESH_CONTROL_TAPER_ELEMENTS");
5491                         aScalarFun = &(SMESHGUI_ComputeScalarValue::Taper);
5492                         break;
5493                 }
5494                 case 6013:
5495                 {
5496                         type = tr("SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
5497                         aScalarFun = &(SMESHGUI_ComputeScalarValue::AspectRatio);
5498                         if (MeshActor->getDisplayMode() != 1)
5499                                 ChangeRepresentation(MeshActor, 1);
5500                         break;
5501                 }
5502                 case 6014:
5503                 {
5504                         type = tr("SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
5505                         aScalarFun = &(SMESHGUI_ComputeScalarValue::MinimumAngle);
5506                         if (MeshActor->getDisplayMode() != 1)
5507                                 ChangeRepresentation(MeshActor, 1);
5508                         break;
5509                 }
5510                 case 6015:
5511                 {
5512                         type = tr("SMESH_CONTROL_WARP_ELEMENTS");
5513                         aScalarFun = &(SMESHGUI_ComputeScalarValue::Warp);
5514                         break;
5515                 }
5516                 case 6016:
5517                 {
5518                         type = tr("SMESH_CONTROL_SKEW_ELEMENTS");
5519                         aScalarFun = &(SMESHGUI_ComputeScalarValue::Skew);
5520                         break;
5521                 }
5522                 }
5523
5524                 for (int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++)
5525                         scalars->InsertTuple1(i, aScalarFun(aDataSet->GetCell(i)));
5526
5527                 float range[2];
5528                 scalars->GetRange(range);
5529
5530                 vtkLookupTable *wat = vtkLookupTable::New();
5531                 wat->SetRange(range);
5532                 wat->Build();
5533
5534                 scalars->SetLookupTable(wat);
5535
5536                 if (!meshMapper)
5537                         meshMapper = (vtkDataSetMapper *) (MeshActor->getMapper());
5538                 meshMapper->SetScalarModeToUseCellData();
5539                 MeshActor->DataSource->GetCellData()->SetScalars(scalars);
5540                 meshMapper->SetScalarRange(range);
5541                 meshMapper->ScalarVisibilityOn();
5542
5543                 vtkScalarBarActor *aScalarBar = GetScalarBar();
5544                 if (aScalarBar == NULL)
5545                 {
5546                         aScalarBar = vtkScalarBarActor::New();
5547                         QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
5548                         QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
5549                         QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
5550                         QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
5551                         QString Orientation =
5552                                 QAD_CONFIG->getSetting("ScalarBar:Orientation");
5553                         float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
5554                         float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
5555                         int NumberOfLabels =
5556                                 QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
5557                         int NumberOfColors =
5558                                 QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
5559
5560                         SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily,
5561                                 Orientation, Width, Height, NumberOfColors, NumberOfLabels);
5562                         vtkRenderer *theRenderer =
5563                                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5564                                 getRightFrame()->getViewFrame())->getRenderer();
5565                         theRenderer->AddActor2D(aScalarBar);
5566                 }
5567                 aScalarBar->SetLookupTable(wat);
5568                 aScalarBar->SetTitle(type.latin1());
5569
5570                 scalars->Delete();
5571                 //    wat->Delete();
5572                 DisplayScalarBar(true);
5573         }
5574         QApplication::restoreOverrideCursor();
5575 }
5576
5577 //=============================================================================
5578 /*!
5579  *
5580  */
5581 //=============================================================================
5582 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor * theScalarBar,
5583         QString Bold, QString Italic,
5584         QString Shadow, QString FontFamily,
5585         QString Orientation, float Width, float Height, int NbColors, int NbLabels)
5586 {
5587         if (Bold.isNull() || Bold.isEmpty() || (Bold.compare("true") == 0))
5588                 theScalarBar->BoldOn();
5589         else
5590                 theScalarBar->BoldOff();
5591
5592         if (Italic.isNull() || Italic.isEmpty() || (Italic.compare("true") == 0))
5593                 theScalarBar->ItalicOn();
5594         else
5595                 theScalarBar->ItalicOff();
5596
5597         if (Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare("true") == 0))
5598                 theScalarBar->ShadowOn();
5599         else
5600                 theScalarBar->ShadowOff();
5601
5602         if (FontFamily.compare("Arial") == 0)
5603                 theScalarBar->SetFontFamilyToArial();
5604         else if (FontFamily.compare("Courier") == 0)
5605                 theScalarBar->SetFontFamilyToCourier();
5606         else if (FontFamily.compare("Times") == 0)
5607                 theScalarBar->SetFontFamilyToTimes();
5608         else
5609                 theScalarBar->SetFontFamilyToArial();
5610
5611         if (Orientation.isNull() || Orientation.isEmpty() ||
5612                 (Orientation.compare("Vertical") == 0))
5613                 theScalarBar->SetOrientationToVertical();
5614         else
5615                 theScalarBar->SetOrientationToHorizontal();
5616
5617         theScalarBar->SetWidth((Width == 0) ? 0.17 : Width);
5618         theScalarBar->SetHeight((Height == 0) ? 0.8 : Height);
5619
5620         theScalarBar->SetNumberOfLabels((NbLabels == 0) ? 5 : NbLabels);
5621         theScalarBar->SetMaximumNumberOfColors((NbColors == 0) ? 64 : NbColors);
5622 }
5623
5624 //=============================================================================
5625 /*!
5626  *
5627  */
5628 //=============================================================================
5629 void SMESHGUI::DisplayScalarBar(bool visibility)
5630 {
5631         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5632                 return;
5633
5634         vtkRenderer *theRenderer =
5635                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5636                 getRightFrame()->getViewFrame())->getRenderer();
5637         vtkScalarBarActor *aScalarBar = GetScalarBar();
5638
5639         if (aScalarBar == NULL)
5640         {
5641                 MESSAGE("myScalarBar is NULL");
5642                 return;
5643         }
5644
5645         if (visibility)
5646                 aScalarBar->VisibilityOn();
5647         else
5648         {
5649                 aScalarBar->VisibilityOff();
5650                 //Turn off mesh coloring (influences on all views)
5651                 vtkActorCollection *actorList = theRenderer->GetActors();
5652                 actorList->InitTraversal();
5653                 vtkActor *ac = actorList->GetNextActor();
5654                 while (ac != NULL)
5655                 {
5656                         if (ac->GetMapper() != NULL)
5657                         {
5658                                 ac->GetMapper()->ScalarVisibilityOff();
5659                         }
5660                         ac = actorList->GetNextActor();
5661                 }
5662                 // Turn off ScalarBar in all views
5663                 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
5664                  * for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
5665                  * if (aFrame->getTypeView() == VIEW_VTK) {
5666                  * vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
5667                  * vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
5668                  * actor2DList->InitTraversal();
5669                  * vtkActor2D* aActor2d =  actor2DList->GetNextActor2D();
5670                  * while (aActor2d != NULL) {
5671                  * if (aActor2d->IsA("vtkScalarBarActor")) {
5672                  * aActor2d->VisibilityOff();
5673                  * break;
5674                  * }
5675                  * actor2DList->GetNextActor2D();
5676                  * }
5677                  * }
5678                  * } */
5679         }
5680         myActiveStudy->update3dViewers();
5681 }
5682
5683 //=============================================================================
5684 /*!
5685  *
5686  */
5687 //=============================================================================
5688 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
5689 {
5690         vtkScalarBarActor *aScalarBar = GetScalarBar();
5691         if (aScalarBar == NULL)
5692         {
5693                 MESSAGE("myScalarBar is NULL");
5694                 return;
5695         }
5696         DisplayScalarBar(false);
5697
5698         aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
5699         vtkRenderer *aRenderer =
5700                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5701                 getRightFrame()->getViewFrame())->getRenderer();
5702         vtkActorCollection *aActorList = aRenderer->GetActors();
5703         aActorList->InitTraversal();
5704         vtkActor *aActor = aActorList->GetNextActor();
5705         while (aActor != NULL)
5706         {
5707                 if (aActor->IsA("SMESH_Actor"))
5708                 {
5709                         SMESH_Actor *aMeshActor = SMESH_Actor::SafeDownCast(aActor);
5710                         vtkDataSetMapper *aMeshMapper =
5711                                 (vtkDataSetMapper *) (aMeshActor->getMapper());
5712                         if ((aMeshMapper != NULL))
5713                         {
5714                                 aMeshMapper->SetScalarRange(MinRange, MaxRange);
5715                                 aMeshMapper->ScalarVisibilityOn();
5716                         }
5717                 }
5718                 aActor = aActorList->GetNextActor();
5719         }
5720         DisplayScalarBar(true);
5721 }
5722
5723 //=============================================================================
5724 /*!
5725  *
5726  */
5727 //=============================================================================
5728 void SMESHGUI::SetDisplaySettings()
5729 {
5730         EmitSignalDeactivateDialog();
5731         SMESHGUI_Preferences_ColorDlg *aDlg =
5732                 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
5733
5734         QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
5735         QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
5736         QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
5737         QColor color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5738         aDlg->SetColor(1, color);
5739
5740         SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
5741         SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
5742         SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
5743         color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5744         aDlg->SetColor(2, color);
5745
5746         SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5747         SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5748         SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5749         color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5750         aDlg->SetColor(3, color);
5751
5752         QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
5753         QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
5754         QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
5755         color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
5756         aDlg->SetColor(4, color);
5757
5758         QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
5759         aDlg->SetIntValue(1, intValue.toInt());
5760         intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
5761         aDlg->SetIntValue(2, intValue.toInt());
5762         intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
5763         aDlg->SetIntValue(3, intValue.toInt());
5764
5765         if (aDlg->exec())
5766         {
5767                 QColor colorFill = aDlg->GetColor(1);
5768                 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
5769                 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen",
5770                         colorFill.green());
5771                 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
5772
5773                 QColor colorOutline = aDlg->GetColor(2);
5774                 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed",
5775                         colorOutline.red());
5776                 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen",
5777                         colorOutline.green());
5778                 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue",
5779                         colorOutline.blue());
5780
5781                 QColor colorNode = aDlg->GetColor(3);
5782                 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
5783                 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen",
5784                         colorNode.green());
5785                 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
5786
5787                 QColor colorBackFace = aDlg->GetColor(4);
5788                 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed",
5789                         colorBackFace.red());
5790                 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen",
5791                         colorBackFace.green());
5792                 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue",
5793                         colorBackFace.blue());
5794
5795                 int width = aDlg->GetIntValue(1);
5796                 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
5797
5798                 int nodes_size = aDlg->GetIntValue(2);
5799                 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
5800
5801                 int shrink_coeff = aDlg->GetIntValue(3);
5802                 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
5803         }
5804
5805         delete aDlg;
5806 }
5807
5808 //=======================================================================
5809 // function : Parameter()
5810 // purpose  : return a parameter (double) from a dialog box
5811 //
5812 //  aValue     : is a double used as a default value displayed
5813 //  aLabel     : is the title for aValue1
5814 //  aTitle     : is the main title
5815 //  bottom     : maximum value to be entered
5816 //  top        : minimum value to be entered
5817 //  decimals   : number of decimals
5818 //=======================================================================
5819 double SMESHGUI::Parameter(Standard_Boolean & res,
5820         const double aValue,
5821         const char *aLabel,
5822         const char *aTitle,
5823         const double bottom, const double top, const int decimals)
5824 {
5825         SMESHGUI_aParameterDlg *Dialog =
5826                 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5827                 aTitle,
5828                 aLabel,
5829                 bottom, top, decimals,
5830                 TRUE);
5831         Dialog->setValue(aValue);
5832         double X = 0.0;
5833         res = (Dialog->exec() == QDialog::Accepted);
5834         if (res)
5835                 X = Dialog->getDblValue();
5836         return X;
5837 }
5838
5839 //=======================================================================
5840 // function : Parameter()
5841 // purpose  : return a parameter (int) from a dialog box
5842 //
5843 //  aValue     : is a int used as a default value displayed
5844 //  aLabel     : is the title for aValue1
5845 //  aTitle     : is the main title
5846 //  bottom     : maximum value to be entered
5847 //  top        : minimum value to be entered
5848 //=======================================================================
5849 int SMESHGUI::Parameter(Standard_Boolean & res,
5850         const int aValue,
5851         const char *aLabel, const char *aTitle, const int bottom, const int top)
5852 {
5853         SMESHGUI_aParameterDlg *Dialog =
5854                 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5855                 aTitle,
5856                 aLabel,
5857                 bottom, top,
5858                 TRUE);
5859         Dialog->setValue(aValue);
5860         int X = 0;
5861         res = (Dialog->exec() == QDialog::Accepted);
5862         if (res)
5863                 X = Dialog->getIntValue();
5864         return X;
5865 }
5866
5867 //=============================================================================
5868 /*!
5869  *
5870  */
5871 //=============================================================================
5872 void SMESHGUI::DisplayEdges(SMESH_Actor * ac, bool visibility)
5873 {
5874         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5875                 return;
5876         if (ac->DataSource == NULL || ac->GetMapper() == NULL)
5877                 return;
5878
5879         vtkGeometryFilter *gf = vtkGeometryFilter::New();
5880         gf->SetInput(ac->DataSource);
5881         vtkFeatureEdges *edges = vtkFeatureEdges::New();
5882         edges->SetInput(gf->GetOutput());
5883         edges->BoundaryEdgesOn();
5884         edges->ManifoldEdgesOn();
5885
5886         vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5887         edgeMapper->SetInput(edges->GetOutput());
5888         edgeMapper->ScalarVisibilityOff();
5889
5890         vtkRenderer *theRenderer =
5891                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5892                 getRightFrame()->getViewFrame())->getRenderer();
5893         vtkActorCollection *actorList = theRenderer->GetActors();
5894
5895         int test = actorList->IsItemPresent(ac->EdgeDevice);
5896         if (test == 0)
5897         {
5898                 vtkProperty *prop = vtkProperty::New();
5899                 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5900                         toFloat() / 255.,
5901                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5902                         toFloat() / 255.,
5903                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5904                         255.);
5905                 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5906                         toInt());
5907                 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5908                         toInt());
5909                 ac->EdgeDevice->SetProperty(prop);
5910                 ac->SetEdgeColor(QAD_CONFIG->
5911                         getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5912                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5913                         toFloat() / 255.,
5914                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5915                         255.);
5916                 ac->EdgeDevice->SetMapper(edgeMapper);
5917
5918                 theRenderer->AddActor(ac->EdgeDevice);
5919         }
5920         else
5921         {
5922                 ac->EdgeDevice->SetMapper(edgeMapper);
5923                 edgeMapper->Update();
5924         }
5925
5926         vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5927         shrink->SetInput(ac->DataSource);
5928         shrink->SetShrinkFactor(ac->GetShrinkFactor());
5929         vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5930         Shrinkgf->SetInput(shrink->GetOutput());
5931         vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5932         ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5933         ShrinkEdges->BoundaryEdgesOn();
5934         ShrinkEdges->ManifoldEdgesOn();
5935
5936         vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5937         ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5938         ShrinkEdgeMapper->ScalarVisibilityOff();
5939
5940         test = actorList->IsItemPresent(ac->EdgeShrinkDevice);
5941         if (test == 0)
5942         {
5943                 vtkProperty *prop = vtkProperty::New();
5944                 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5945                         toFloat() / 255.,
5946                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5947                         toFloat() / 255.,
5948                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5949                         255.);
5950                 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5951                         toInt());
5952                 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5953                         toInt());
5954                 ac->EdgeShrinkDevice->SetProperty(prop);
5955                 ac->SetEdgeColor(QAD_CONFIG->
5956                         getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5957                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5958                         toFloat() / 255.,
5959                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5960                         255.);
5961                 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5962
5963                 theRenderer->AddActor(ac->EdgeShrinkDevice);
5964         }
5965         else
5966         {
5967                 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5968                 ShrinkEdgeMapper->Update();
5969         }
5970
5971         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5972         renWin->Render();
5973 }
5974
5975 //=============================================================================
5976 /*!
5977  *
5978  */
5979 //=============================================================================
5980 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5981 {
5982         SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh(aMesh);
5983         SALOMEDS::GenericAttribute_var anAttr;
5984         SALOMEDS::AttributeName_var aName;
5985         if (!aSO_M->_is_nil())
5986         {
5987                 if (aSO_M->FindAttribute(anAttr, "AttributeName"))
5988                 {
5989                         aName = SALOMEDS::AttributeName::_narrow(anAttr);
5990                         Standard_Boolean result;
5991                         SMESH_Actor *MeshActor =
5992                                 smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5993                         if (!result)
5994                         {
5995                                 SMESH_Actor *amesh = SMESH_Actor::New();
5996                                 Handle(SALOME_InteractiveObject) IO =
5997                                         new SALOME_InteractiveObject(aSO_M->GetID(), "MESH",
5998                                         aName->Value());
5999                                 amesh->setIO(IO);
6000                                 amesh->setName(aName->Value());
6001                                 DisplayActor(amesh, false);
6002                         }
6003                 }
6004         }
6005 }
6006
6007 //=============================================================================
6008 /*!
6009  *
6010  */
6011 //=============================================================================
6012 void SMESHGUI::Update()
6013 {
6014         if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
6015         {                                                       //VTK
6016                 vtkRenderer *theRenderer =
6017                         ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6018                         getRightFrame()->getViewFrame())->getRenderer();
6019
6020                 SALOME_Selection *Sel =
6021                         SALOME_Selection::Selection(myActiveStudy->getSelection());
6022                 int nbSel = Sel->IObjectCount();
6023                 if (nbSel == 0)
6024                 {
6025                         vtkActorCollection *actorList = theRenderer->GetActors();
6026                         actorList->InitTraversal();
6027                         vtkActor *ac = actorList->GetNextActor();
6028                         while (!(ac == NULL))
6029                         {
6030                                 if (ac->IsA("SMESH_Actor"))
6031                                 {
6032                                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
6033                                         if (anActor->hasIO())
6034                                         {
6035                                                 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
6036                                                 Update(IO);
6037                                         }
6038                                 }
6039                                 ac = actorList->GetNextActor();
6040                         }
6041                 }
6042                 else
6043                 {
6044                         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
6045                         for (; It.More(); It.Next())
6046                         {
6047                                 Handle(SALOME_InteractiveObject) IO = It.Value();
6048                                 Update(IO);
6049                         }
6050                 }
6051                 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6052                 renWin->Render();
6053         }
6054         QApplication::restoreOverrideCursor();
6055 }
6056
6057 //=============================================================================
6058 /*!
6059  *
6060  */
6061 //=============================================================================
6062 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject) & IO)
6063 {
6064         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6065                 return;
6066
6067         if (IO->hasEntry())
6068         {
6069                 Standard_Boolean res;
6070                 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh(IO, res);
6071                 if (res)
6072                 {
6073                         SMESH_Actor *ac = FindActorByEntry(IO->getEntry(), res, false);
6074                         if (res)
6075                         {
6076                                 // Check whether the actor belongs to the active view
6077                                 VTKViewer_RenderWindowInteractor *rwInter =
6078                                         ((VTKViewer_ViewFrame *) myActiveStudy->
6079                                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
6080                                         getRWInteractor();
6081
6082                                 ac = ReadScript(aMesh);
6083                                 // The actor belongs to inactive view -> create a copy and display it in the active view
6084                                 if (!rwInter->isInViewer(IO))
6085                                 {
6086                                         SMESH_Actor *acCopy = SMESH_Actor::New();
6087                                         acCopy->ShallowCopy(ac);
6088                                         ac=acCopy;
6089                                 }
6090
6091                                 if (ac != NULL)
6092                                 {
6093 #ifdef TRACE
6094                                         Dump(ac);
6095 #endif
6096                                         DisplayActor(ac);
6097                                         DisplayEdges(ac);
6098                                         smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
6099                                 }
6100                         }
6101                 }
6102         }
6103 }
6104
6105 //=============================================================================
6106 /*!
6107  *
6108  */
6109 //=============================================================================
6110 vtkActor *SMESHGUI::SimulationMoveNode(SMESH_Actor * Mactor, int idnode)
6111 {
6112         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6113                 return NULL;
6114
6115         mySimulationActors = vtkActorCollection::New();
6116         vtkRenderer *theRenderer =
6117                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6118                 getRightFrame()->getViewFrame())->getRenderer();
6119
6120         vtkUnstructuredGrid *ugrid =
6121                 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
6122         vtkIdList *IdCells = vtkIdList::New();
6123         ugrid->GetPointCells(idnode, IdCells);
6124
6125         vtkPoints *Pts = vtkPoints::New();
6126         Pts = ugrid->GetPoints();
6127
6128         vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
6129         ugridSimulation->SetPoints(Pts);
6130         vtkIdList *IdPts = vtkIdList::New();
6131         for (int j = 0; j < IdCells->GetNumberOfIds(); j++)
6132         {
6133                 ugrid->GetCellPoints(IdCells->GetId(j), IdPts);
6134                 ugridSimulation->InsertNextCell(ugrid->GetCellType(IdCells->GetId(j)),
6135                         IdPts);
6136         }
6137
6138         vtkProperty *prop = vtkProperty::New();
6139         prop->SetColor(1., 0., 0.);
6140         prop->SetRepresentationToWireframe();
6141
6142         int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
6143         if (Edgewidth == 0)
6144                 Edgewidth = 1;
6145         prop->SetLineWidth(Edgewidth + 1);
6146
6147         vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6148         Mapper->SetInput(ugridSimulation);
6149         vtkActor *ac = vtkActor::New();
6150         ac->SetMapper(Mapper);
6151         ac->SetProperty(prop);
6152
6153         ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
6154         ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
6155
6156         mySimulationActors->AddItem(ac);
6157         theRenderer->AddActor(ac);
6158
6159         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6160         renWin->Render();
6161
6162         return ac;
6163 }
6164
6165 //=============================================================================
6166 /*!
6167  *
6168  */
6169 //=============================================================================
6170 void SMESHGUI::DisplaySimulationNode(SMESH::SMESH_Mesh_ptr aMesh, float x,
6171         float y, float z)
6172 {
6173         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6174                 return;
6175
6176         EraseSimulationActors();
6177         mySimulationActors = vtkActorCollection::New();
6178         vtkRenderer *theRenderer =
6179                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6180                 getRightFrame()->getViewFrame())->getRenderer();
6181         Standard_Boolean result;
6182         SMESH_Actor *ac = FindActor(aMesh, result, true);
6183
6184         if (result)
6185         {
6186                 vtkUnstructuredGrid *ugrid =
6187                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6188                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6189
6190                 vtkPoints *Pts = ugrid->GetPoints();
6191                 vtkPoints *newPts = vtkPoints::New();
6192                 int nbPts = Pts->GetNumberOfPoints();
6193                 for (int i = 0; i < nbPts; i++)
6194                 {
6195                         newPts->InsertPoint(i, Pts->GetPoint(i));
6196                 }
6197
6198                 newugrid->SetPoints(newPts);
6199                 newugrid->GetPoints()->InsertNextPoint(x, y, z);
6200
6201                 vtkMaskPoints *verts = vtkMaskPoints::New();
6202                 verts->SetInput(newugrid);
6203                 verts->SetGenerateVertices(1);
6204                 verts->SetOnRatio(1);
6205
6206                 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
6207                 vertMapper->SetInput(verts->GetOutput());
6208                 vertMapper->ScalarVisibilityOff();
6209
6210                 vtkActor *node = vtkActor::New();
6211                 node->SetMapper(vertMapper);
6212
6213                 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
6214                 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
6215                 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
6216                 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
6217                 if (!nodecolor.isValid())
6218 //       nodecolor = QColor(0.,1.,0.);
6219                         nodecolor = QColor(0, 1, 0);
6220
6221                 node->GetProperty()->SetColor(float (nodecolor.red()) / 255.,
6222                         float (nodecolor.green()) / 255., float (nodecolor.blue()) / 255.);
6223
6224                 int intValue =
6225                         QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
6226                 if (intValue < 1)
6227                         intValue == 1;
6228
6229                 node->GetProperty()->SetPointSize(intValue);
6230
6231                 node->VisibilityOn();
6232
6233                 mySimulationActors->AddItem(node);
6234                 theRenderer->AddActor(node);
6235         }
6236
6237         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6238         renWin->Render();
6239 }
6240
6241 //=============================================================================
6242 /*!
6243  *
6244  */
6245 //=============================================================================
6246 void SMESHGUI::DisplaySimulationMoveNode(vtkActor * ac, int idnode, float x,
6247         float y, float z)
6248 {
6249         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6250                 return;
6251
6252         vtkRenderer *theRenderer =
6253                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6254                 getRightFrame()->getViewFrame())->getRenderer();
6255         float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
6256         pt[0] = x;
6257         pt[1] = y;
6258         pt[2] = z;
6259
6260         ac->GetMapper()->ImmediateModeRenderingOn();
6261         ac->GetProperty()->SetRepresentationToWireframe();
6262
6263         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6264
6265         renWin->Render();
6266 }
6267
6268 //=============================================================================
6269 /*!
6270  *
6271  */
6272 //=============================================================================
6273 void SMESHGUI::MoveNode(SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x,
6274         float y, float z)
6275 {
6276         Standard_Boolean result;
6277
6278         SMESH_Actor *MeshActor = FindActor(aMesh, result, true);
6279         if (result)
6280         {
6281         }
6282 }
6283
6284 //=============================================================================
6285 /*!
6286  *
6287  */
6288 //=============================================================================
6289 void SMESHGUI::ScalarVisibilityOff()
6290 {
6291         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6292                 return;
6293
6294         vtkRenderer *theRenderer =
6295                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6296                 getRightFrame()->getViewFrame())->getRenderer();
6297         vtkActorCollection *actorList = theRenderer->GetActors();
6298
6299         actorList->InitTraversal();
6300         vtkActor *ac = actorList->GetNextActor();
6301         while (!(ac == NULL))
6302         {
6303                 if (ac->IsA("SMESH_Actor"))
6304                 {
6305                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
6306                         if (anActor->GetVisibility() == 1)
6307                         {
6308                                 vtkDataSetMapper *meshMapper =
6309                                         (vtkDataSetMapper *) (anActor->getMapper());
6310                                 meshMapper->ScalarVisibilityOff();
6311                                 meshMapper->SetInput(anActor->DataSource);
6312                                 ChangeRepresentation(anActor, anActor->getDisplayMode());
6313                         }
6314                 }
6315                 ac = actorList->GetNextActor();
6316         }
6317
6318         theRenderer->Render();
6319 }
6320
6321 //=============================================================================
6322 /*!
6323  *
6324  */
6325 //=============================================================================
6326 void SMESHGUI::DisplaySimulationEdge(SMESH::SMESH_Mesh_ptr aMesh,
6327         const TColStd_MapOfInteger & MapIndex)
6328 {
6329         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6330                 return;
6331
6332         EraseSimulationActors();
6333         mySimulationActors = vtkActorCollection::New();
6334         vtkRenderer *theRenderer =
6335                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6336                 getRightFrame()->getViewFrame())->getRenderer();
6337         Standard_Boolean result;
6338         SMESH_Actor *ac = FindActor(aMesh, result, true);
6339         if (result)
6340         {
6341                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6342                 int idNodes[2];
6343                 int pts[2];
6344                 int i = 0;
6345                 vtkIdList *Ids = vtkIdList::New();
6346                 for (; ite.More(); ite.Next())
6347                 {
6348                         idNodes[i] = ite.Key();
6349                         i++;
6350                 }
6351
6352                 Ids->InsertId(0, idNodes[0]);
6353                 pts[0] = idNodes[0];
6354                 Ids->InsertId(1, idNodes[1]);
6355                 pts[1] = idNodes[1];
6356
6357                 vtkUnstructuredGrid *ugrid =
6358                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6359                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6360                 newugrid->SetPoints(ugrid->GetPoints());
6361                 newugrid->InsertNextCell(VTK_LINE, 2, pts);
6362
6363                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6364                 Mapper->SetInput(newugrid);
6365                 Mapper->Update();
6366
6367                 vtkActor *edge = vtkActor::New();
6368                 edge->SetMapper(Mapper);
6369                 edge->SetProperty(ac->GetProperty());
6370                 edge->SetBackfaceProperty(ac->GetBackfaceProperty());
6371                 edge->VisibilityOn();
6372                 mySimulationActors->AddItem(edge);
6373                 theRenderer->AddActor(edge);
6374         }
6375
6376         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6377         renWin->Render();
6378 }
6379
6380 //=============================================================================
6381 /*!
6382  *
6383  */
6384 //=============================================================================
6385 void SMESHGUI::DisplaySimulationTriangle(SMESH::SMESH_Mesh_ptr aMesh,
6386         const TColStd_MapOfInteger & MapIndex, bool reverse)
6387 {
6388         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6389                 return;
6390
6391         EraseSimulationActors();
6392         mySimulationActors = vtkActorCollection::New();
6393         vtkRenderer *theRenderer =
6394                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6395                 getRightFrame()->getViewFrame())->getRenderer();
6396         Standard_Boolean result;
6397         SMESH_Actor *ac = FindActor(aMesh, result, true);
6398         if (result)
6399         {
6400                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6401                 int idNodes[3];
6402                 int pts[3];
6403                 int i = 0;
6404                 vtkIdList *Ids = vtkIdList::New();
6405                 for (; ite.More(); ite.Next())
6406                 {
6407                         idNodes[i] = ite.Key();
6408                         i++;
6409                 }
6410
6411                 if (reverse)
6412                 {
6413                         Ids->InsertId(0, idNodes[2]);
6414                         pts[0] = idNodes[2];
6415                         Ids->InsertId(1, idNodes[1]);
6416                         pts[1] = idNodes[1];
6417                         Ids->InsertId(2, idNodes[0]);
6418                         pts[2] = idNodes[0];
6419                 }
6420                 else
6421                 {
6422                         Ids->InsertId(0, idNodes[0]);
6423                         pts[0] = idNodes[0];
6424                         Ids->InsertId(1, idNodes[1]);
6425                         pts[1] = idNodes[1];
6426                         Ids->InsertId(2, idNodes[2]);
6427                         pts[2] = idNodes[2];
6428                 }
6429                 vtkUnstructuredGrid *ugrid =
6430                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6431                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6432                 newugrid->SetPoints(ugrid->GetPoints());
6433                 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
6434
6435                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6436                 Mapper->SetInput(newugrid);
6437                 Mapper->Update();
6438
6439                 vtkActor *tri = vtkActor::New();
6440                 tri->SetMapper(Mapper);
6441                 tri->SetProperty(ac->GetProperty());
6442                 tri->SetBackfaceProperty(ac->GetBackfaceProperty());
6443                 tri->VisibilityOn();
6444                 mySimulationActors->AddItem(tri);
6445                 theRenderer->AddActor(tri);
6446         }
6447
6448         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6449         renWin->Render();
6450 }
6451
6452 //=============================================================================
6453 /*!
6454  *
6455  */
6456 //=============================================================================
6457 void SMESHGUI::DisplaySimulationQuadrangle(SMESH::SMESH_Mesh_ptr aMesh,
6458         const TColStd_MapOfInteger & MapIndex, bool reverse)
6459 {
6460         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6461                 return;
6462
6463         EraseSimulationActors();
6464         mySimulationActors = vtkActorCollection::New();
6465         vtkRenderer *theRenderer =
6466                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6467                 getRightFrame()->getViewFrame())->getRenderer();
6468         Standard_Boolean result;
6469         SMESH_Actor *ac = FindActor(aMesh, result, true);
6470
6471         vtkUnstructuredGrid *ugrid =
6472                 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6473
6474         if (result)
6475         {
6476                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6477                 int i = 0;
6478                 int idNodes[4];
6479                 vtkIdList *Ids = vtkIdList::New();
6480                 for (; ite.More(); ite.Next())
6481                 {
6482                         idNodes[i] = ite.Key();
6483                         i++;
6484                 }
6485
6486                 float *p0 = ugrid->GetPoint(idNodes[0]);
6487                 float *p1 = ugrid->GetPoint(idNodes[1]);
6488                 float *p2 = ugrid->GetPoint(idNodes[2]);
6489                 float *p3 = ugrid->GetPoint(idNodes[3]);
6490
6491                 gp_Pnt P0(p0[0], p0[1], p0[2]);
6492
6493                 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6494                 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6495                 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6496
6497                 gp_Vec Cross1 = V1 ^ V2;
6498                 gp_Vec Cross2 = V2 ^ V3;
6499
6500                 int tmp;
6501                 if (Cross1.Dot(Cross2) < 0)
6502                 {
6503                         V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6504                         V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6505                         Cross1 = V1 ^ V2;
6506                         Cross2 = V2 ^ V3;
6507
6508                         if (Cross1.Dot(Cross2) < 0)
6509                         {
6510                                 tmp = idNodes[2];
6511                                 idNodes[2] = idNodes[3];
6512                                 idNodes[3] = tmp;
6513                         }
6514                         else
6515                         {
6516                                 tmp = idNodes[1];
6517                                 idNodes[1] = idNodes[2];
6518                                 idNodes[2] = tmp;
6519                         }
6520                 }
6521
6522                 if (reverse)
6523                 {
6524                         Ids->InsertId(0, idNodes[3]);
6525                         Ids->InsertId(1, idNodes[2]);
6526                         Ids->InsertId(2, idNodes[1]);
6527                         Ids->InsertId(3, idNodes[0]);
6528                 }
6529                 else
6530                 {
6531                         Ids->InsertId(0, idNodes[0]);
6532                         Ids->InsertId(1, idNodes[1]);
6533                         Ids->InsertId(2, idNodes[2]);
6534                         Ids->InsertId(3, idNodes[3]);
6535                 }
6536
6537                 //    vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
6538                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6539                 newugrid->SetPoints(ugrid->GetPoints());
6540                 newugrid->InsertNextCell(VTK_QUAD, Ids);
6541
6542                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6543                 Mapper->SetInput(newugrid);
6544                 Mapper->Update();
6545
6546                 vtkActor *quad = vtkActor::New();
6547                 quad->SetMapper(Mapper);
6548                 quad->SetProperty(ac->GetProperty());
6549                 quad->SetBackfaceProperty(ac->GetBackfaceProperty());
6550                 quad->VisibilityOn();
6551                 mySimulationActors->AddItem(quad);
6552                 theRenderer->AddActor(quad);
6553         }
6554         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6555         renWin->Render();
6556 }
6557
6558 //=============================================================================
6559 /*!
6560  *
6561  */
6562 //=============================================================================
6563 void SMESHGUI::DisplaySimulationTetra(SMESH::SMESH_Mesh_ptr aMesh,
6564         const TColStd_MapOfInteger & MapIndex)
6565 {
6566         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6567                 return;
6568
6569         EraseSimulationActors();
6570         mySimulationActors = vtkActorCollection::New();
6571         vtkRenderer *theRenderer =
6572                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6573                 getRightFrame()->getViewFrame())->getRenderer();
6574         Standard_Boolean result;
6575         SMESH_Actor *ac = FindActor(aMesh, result, true);
6576         if (result)
6577         {
6578                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6579                 int i = 0;
6580                 int idNodes[4];
6581                 vtkIdList *Ids = vtkIdList::New();
6582                 for (; ite.More(); ite.Next())
6583                 {
6584                         idNodes[i] = ite.Key();
6585                         i++;
6586                 }
6587
6588                 Ids->InsertId(0, idNodes[0]);
6589                 Ids->InsertId(1, idNodes[1]);
6590                 Ids->InsertId(2, idNodes[2]);
6591                 Ids->InsertId(3, idNodes[3]);
6592
6593                 vtkUnstructuredGrid *ugrid =
6594                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6595                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6596                 newugrid->SetPoints(ugrid->GetPoints());
6597                 newugrid->InsertNextCell(VTK_TETRA, Ids);
6598
6599                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6600                 Mapper->SetInput(newugrid);
6601                 Mapper->Update();
6602
6603                 vtkActor *tetra = vtkActor::New();
6604                 tetra->SetMapper(Mapper);
6605                 tetra->SetProperty(ac->GetProperty());
6606                 tetra->SetBackfaceProperty(ac->GetBackfaceProperty());
6607                 tetra->VisibilityOn();
6608                 mySimulationActors->AddItem(tetra);
6609                 theRenderer->AddActor(tetra);
6610         }
6611         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6612         renWin->Render();
6613 }
6614
6615 //=============================================================================
6616 /*!
6617  *
6618  */
6619 //=============================================================================
6620 void SMESHGUI::DisplaySimulationHexa(SMESH::SMESH_Mesh_ptr aMesh,
6621         const TColStd_MapOfInteger & MapIndex)
6622 {
6623         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6624                 return;
6625
6626         EraseSimulationActors();
6627         mySimulationActors = vtkActorCollection::New();
6628         vtkRenderer *theRenderer =
6629                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6630                 getRightFrame()->getViewFrame())->getRenderer();
6631         Standard_Boolean result;
6632         SMESH_Actor *ac = FindActor(aMesh, result, true);
6633         if (result)
6634         {
6635                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6636                 int i = 0;
6637                 int idNodes[8];
6638                 vtkIdList *Ids = vtkIdList::New();
6639                 for (; ite.More(); ite.Next())
6640                 {
6641                         idNodes[i] = ite.Key();
6642                         i++;
6643                 }
6644
6645                 Ids->InsertId(0, idNodes[0]);
6646                 Ids->InsertId(1, idNodes[1]);
6647                 Ids->InsertId(2, idNodes[2]);
6648                 Ids->InsertId(3, idNodes[3]);
6649                 Ids->InsertId(4, idNodes[4]);
6650                 Ids->InsertId(5, idNodes[5]);
6651                 Ids->InsertId(6, idNodes[6]);
6652                 Ids->InsertId(7, idNodes[7]);
6653
6654                 vtkUnstructuredGrid *ugrid =
6655                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6656                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6657                 newugrid->SetPoints(ugrid->GetPoints());
6658                 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
6659
6660                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6661                 Mapper->SetInput(newugrid);
6662                 Mapper->Update();
6663
6664                 vtkActor *hexa = vtkActor::New();
6665                 hexa->SetMapper(Mapper);
6666                 hexa->SetProperty(ac->GetProperty());
6667                 hexa->SetBackfaceProperty(ac->GetBackfaceProperty());
6668                 hexa->VisibilityOn();
6669                 mySimulationActors->AddItem(hexa);
6670                 theRenderer->AddActor(hexa);
6671         }
6672         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6673         renWin->Render();
6674 }
6675
6676 //=============================================================================
6677 /*!
6678  *
6679  */
6680 //=============================================================================
6681 void SMESHGUI::AddFace(SMESH::SMESH_Mesh_ptr aMesh,
6682         const TColStd_MapOfInteger & MapIndex, bool reverse)
6683 {
6684         QApplication::setOverrideCursor(Qt::waitCursor);
6685         Standard_Boolean result;
6686         SMESH_Actor *ac = FindActor(aMesh, result, true);
6687         if (result)
6688         {
6689                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6690                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6691                 anArrayOfIdeces->length(MapIndex.Extent());
6692
6693                 int i = 0;
6694                 for (; ite.More(); ite.Next())
6695                 {
6696                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6697                         i++;
6698                 }
6699
6700                 int tmp;
6701                 if (MapIndex.Extent() == 4)
6702                 {
6703                         int idNodes[4];
6704                         int i = 0;
6705                         TColStd_MapIteratorOfMapOfInteger ite1(MapIndex);
6706                         for (; ite1.More(); ite1.Next())
6707                         {
6708                                 idNodes[i] = ite1.Key();
6709                                 i++;
6710                         }
6711
6712                         vtkUnstructuredGrid *ugrid =
6713                                 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6714                         float *p0 = ugrid->GetPoint(idNodes[0]);
6715                         float *p1 = ugrid->GetPoint(idNodes[1]);
6716                         float *p2 = ugrid->GetPoint(idNodes[2]);
6717                         float *p3 = ugrid->GetPoint(idNodes[3]);
6718
6719                         gp_Pnt P0(p0[0], p0[1], p0[2]);
6720
6721                         gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6722                         gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6723                         gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6724
6725                         gp_Vec Cross1 = V1 ^ V2;
6726                         gp_Vec Cross2 = V2 ^ V3;
6727
6728                         if (Cross1.Dot(Cross2) < 0)
6729                         {
6730
6731                                 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6732                                 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6733                                 Cross1 = V1 ^ V2;
6734                                 Cross2 = V2 ^ V3;
6735
6736                                 if (Cross1.Dot(Cross2) < 0)
6737                                 {
6738                                         tmp = anArrayOfIdeces[2];
6739                                         anArrayOfIdeces[2] = anArrayOfIdeces[3];
6740                                         anArrayOfIdeces[3] = tmp;
6741                                 }
6742                                 else
6743                                 {
6744                                         tmp = anArrayOfIdeces[1];
6745                                         anArrayOfIdeces[1] = anArrayOfIdeces[2];
6746                                         anArrayOfIdeces[2] = tmp;
6747                                 }
6748                         }
6749                 }
6750
6751                 //    int tmp;
6752                 if (reverse)
6753                 {
6754                         for (i = 0; i < (MapIndex.Extent() / 2); i++)
6755                         {
6756                                 tmp = anArrayOfIdeces[i];
6757                                 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent() - i - 1];
6758                                 anArrayOfIdeces[MapIndex.Extent() - i - 1] = tmp;
6759                         }
6760                 }
6761                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6762                 aMeshEditor->AddFace(anArrayOfIdeces);
6763         }
6764         if (myAutomaticUpdate)
6765         {
6766                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6767                 if (Mesh != NULL)
6768                 {
6769                         smeshGUI->DisplayActor(Mesh);
6770                         smeshGUI->DisplayEdges(Mesh);
6771                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6772                         AddActorInSelection(Mesh);
6773                 }
6774         }
6775         QApplication::restoreOverrideCursor();
6776 }
6777
6778 //=============================================================================
6779 /*!
6780  *
6781  */
6782 //=============================================================================
6783 void SMESHGUI::AddVolume(SMESH::SMESH_Mesh_ptr aMesh,
6784         const TColStd_MapOfInteger & MapIndex)
6785 {
6786         QApplication::setOverrideCursor(Qt::waitCursor);
6787         Standard_Boolean result;
6788         SMESH_Actor *ac = FindActor(aMesh, result, true);
6789         if (result)
6790         {
6791                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6792                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6793                 anArrayOfIdeces->length(MapIndex.Extent());
6794
6795                 int i = 0;
6796                 for (; ite.More(); ite.Next())
6797                 {
6798                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6799                         i++;
6800                 }
6801
6802                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6803                 aMeshEditor->AddVolume(anArrayOfIdeces);
6804         }
6805         if (myAutomaticUpdate)
6806         {
6807                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6808                 if (Mesh != NULL)
6809                 {
6810                         smeshGUI->DisplayActor(Mesh);
6811                         smeshGUI->DisplayEdges(Mesh);
6812                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6813                         AddActorInSelection(Mesh);
6814                 }
6815         }
6816         QApplication::restoreOverrideCursor();
6817 }
6818
6819 //=============================================================================
6820 /*!
6821  *
6822  */
6823 //=============================================================================
6824 void SMESHGUI::AddEdge(SMESH::SMESH_Mesh_ptr aMesh,
6825         const TColStd_MapOfInteger & MapIndex)
6826 {
6827         QApplication::setOverrideCursor(Qt::waitCursor);
6828         Standard_Boolean result;
6829         SMESH_Actor *ac = FindActor(aMesh, result, true);
6830         if (result)
6831         {
6832                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6833                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6834                 anArrayOfIdeces->length(MapIndex.Extent());
6835
6836                 int i = 0;
6837                 for (; ite.More(); ite.Next())
6838                 {
6839                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6840                         i++;
6841                 }
6842
6843                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6844                 aMeshEditor->AddEdge(anArrayOfIdeces);
6845         }
6846         if (myAutomaticUpdate)
6847         {
6848                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6849                 if (Mesh != NULL)
6850                 {
6851                         smeshGUI->DisplayActor(Mesh);
6852                         smeshGUI->DisplayEdges(Mesh);
6853                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6854                         AddActorInSelection(Mesh);
6855                 }
6856         }
6857         QApplication::restoreOverrideCursor();
6858 }
6859
6860 //=============================================================================
6861 /*!
6862  *
6863  */
6864 //=============================================================================
6865 void SMESHGUI::AddNode(SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
6866 {
6867         QApplication::setOverrideCursor(Qt::waitCursor);
6868         Standard_Boolean result;
6869         SMESH_Actor *ac = FindActor(aMesh, result, true);
6870         if (result)
6871         {
6872                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6873                 aMeshEditor->AddNode(x, y, z);
6874
6875                 if (myAutomaticUpdate)
6876                 {
6877                         SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6878                         if (Mesh != NULL)
6879                         {
6880                                 smeshGUI->DisplayActor(Mesh);
6881                                 smeshGUI->DisplayEdges(Mesh);
6882                                 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6883                                 AddActorInSelection(Mesh);
6884                         }
6885                 }
6886         }
6887         QApplication::restoreOverrideCursor();
6888 }
6889
6890 //=============================================================================
6891 /*!
6892  *
6893  */
6894 //=============================================================================
6895 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor * ac)
6896 {
6897         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6898                 return;
6899
6900         EraseSimulationActors();
6901         mySimulationActors2D = vtkActor2DCollection::New();
6902
6903         vtkRenderer *theRenderer =
6904                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6905                 getRightFrame()->getViewFrame())->getRenderer();
6906
6907         vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
6908         gs2->SetGlyphTypeToTriangle();
6909         gs2->FilledOff();
6910
6911         vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
6912         legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
6913         legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.);       //relative to Position
6914
6915         legend->SetNumberOfEntries(4);
6916         legend->SetEntryString(0, tr("SMESH_BOUNDARYEDGES"));
6917         legend->SetEntrySymbol(0, gs2->GetOutput());
6918         legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.));
6919         legend->SetEntryString(1, tr("SMESH_MANIFOLDEDGES"));
6920         legend->SetEntrySymbol(1, gs2->GetOutput());
6921         legend->SetEntryColor(1,
6922                 ac->GetMapper()->GetLookupTable()->GetColor(0.666667));
6923         legend->SetEntryString(2, tr("SMESH_NONMANIFOLDEDGES"));
6924         legend->SetEntrySymbol(2, gs2->GetOutput());
6925         legend->SetEntryColor(2,
6926                 ac->GetMapper()->GetLookupTable()->GetColor(0.222222));
6927         legend->SetEntryString(3, tr("SMESH_FEATUREEDGES"));
6928         legend->SetEntrySymbol(3, gs2->GetOutput());
6929         legend->SetEntryColor(3,
6930                 ac->GetMapper()->GetLookupTable()->GetColor(0.444444));
6931         legend->SetPadding(5);
6932         //  legend->GetProperty()->SetColor();
6933
6934         mySimulationActors2D->AddItem(legend);
6935         theRenderer->AddActor2D(legend);
6936
6937         // Update the view
6938         myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->
6939                 Repaint();
6940 }
6941
6942 //===============================================================================
6943 // function : OnEditDelete()
6944 // purpose  :
6945 //===============================================================================
6946 void SMESHGUI::OnEditDelete()
6947 {
6948         if (QAD_MessageBox::warn2
6949                 (QAD_Application::getDesktop(),
6950                         tr("SMESH_WRN_WARNING"),
6951                         tr("SMESH_REALLY_DELETE"),
6952                         tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
6953                 return;
6954
6955         int nbSf = myActiveStudy->getStudyFramesCount();
6956
6957         Standard_Boolean found;
6958         SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
6959         SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
6960         SALOMEDS::GenericAttribute_var anAttr;
6961         SALOMEDS::AttributeIOR_var anIOR;
6962
6963         SALOME_Selection *Sel =
6964                 SALOME_Selection::Selection(myActiveStudy->getSelection());
6965         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
6966         for (; It.More(); It.Next())
6967         {
6968                 Handle(SALOME_InteractiveObject) IObject = It.Value();
6969                 if (IObject->hasEntry())
6970                 {
6971                         SALOMEDS::SObject_var SO =
6972                                 myStudy->FindObjectID(IObject->getEntry());
6973
6974                         /* Erase child graphical objects */
6975                         SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
6976                         for (; it->More(); it->Next())
6977                         {
6978                                 SALOMEDS::SObject_var CSO = it->Value();
6979                                 if (CSO->FindAttribute(anAttr, "AttributeIOR"))
6980                                 {
6981                                         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6982
6983                                         for (int i = 0; i < nbSf; i++)
6984                                         {
6985                                                 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
6986                                                 if (sf->getTypeView() == VIEW_VTK)
6987                                                 {
6988                                                         vtkRenderer *Renderer =
6989                                                                 ((VTKViewer_ViewFrame *) smeshGUI->
6990                                                                 myActiveStudy->getActiveStudyFrame()->
6991                                                                 getRightFrame()->getViewFrame())->getRenderer();
6992                                                         SMESH_Actor *ac =
6993                                                                 smeshGUI->FindActorByEntry(CSO->GetID(), found,
6994                                                                 false);
6995                                                         if (found)
6996                                                         {
6997                                                                 Renderer->RemoveActor(ac->EdgeDevice);
6998                                                                 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6999                                                                 Renderer->RemoveActor(ac);
7000                                                         }
7001                                                 }
7002                                         }
7003                                 }
7004                         }
7005
7006                         /* Erase main graphical object */
7007                         for (int i = 0; i < nbSf; i++)
7008                         {
7009                                 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
7010                                 if (sf->getTypeView() == VIEW_VTK)
7011                                 {
7012                                         vtkRenderer *Renderer =
7013                                                 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
7014                                                 getActiveStudyFrame()->getRightFrame()->
7015                                                 getViewFrame())->getRenderer();
7016                                         VTKViewer_RenderWindowInteractor *myRenderInter =
7017                                                 ((VTKViewer_ViewFrame *) sf->getRightFrame()->
7018                                                 getViewFrame())->getRWInteractor();
7019                                         SMESH_Actor *ac =
7020                                                 smeshGUI->FindActorByEntry(IObject->getEntry(), found,
7021                                                 false);
7022                                         if (found)
7023                                         {
7024                                                 Renderer->RemoveActor(ac->EdgeDevice);
7025                                                 Renderer->RemoveActor(ac->EdgeShrinkDevice);
7026                                         }
7027                                         myRenderInter->Remove(IObject);
7028                                 }
7029                         }
7030
7031                         /* Erase objects in Study */
7032                         SALOMEDS::SObject_var obj =
7033                                 myStudy->FindObjectID(IObject->getEntry());
7034                         if (!obj->_is_nil())
7035                         {
7036                                 QAD_Operation *op =
7037                                         new SALOMEGUI_ImportOperation(myActiveStudy);
7038                                 op->start();
7039                                 aStudyBuilder->RemoveObject(obj);
7040                                 op->finish();
7041                         }
7042
7043                 }                                               /* IObject->hasEntry() */
7044         }                                                       /* more/next           */
7045
7046         /* Clear any previous selection */
7047         Sel->ClearIObjects();
7048         myActiveStudy->updateObjBrowser();
7049 }