Salome HOME
Merge br_enable_import_mesh. Enable import mesh and save/load SMESH study.
[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 // QT Includes
91 #define  INCLUDE_MENUITEM_DEF
92 #include <qapplication.h>
93 #include <qlineedit.h>
94 #include <qmenudata.h>
95 #include <qmenubar.h>
96 #include <qpopupmenu.h>
97 #include <qfont.h>
98 #include <qstring.h>
99 #include <qcheckbox.h>
100 #include <qcolordialog.h>
101 #include <qmessagebox.h>
102 #include <qspinbox.h>
103 #include <qlist.h>
104 #include <qwidget.h>
105 #include <qevent.h>
106 #include <qradiobutton.h>
107
108 // VTK Includes
109 #include "VTKViewer_Common.h"
110 #include "VTKViewer_ViewFrame.h"
111 #include <vtkLegendBoxActor.h>
112 #include <vtkFeatureEdges.h>
113 #include <vtkDoubleArray.h>
114
115 // Open CASCADE Includes
116 #include <gp_Pnt.hxx>
117 #include <gp_Vec.hxx>
118
119 static GEOM_Client ShapeReader;
120 static SMESHGUI *smeshGUI = 0;
121 static CORBA::ORB_var _orb;
122
123 //=============================================================================
124 /*!
125  *
126  */
127 //=============================================================================
128 class CustomItem:public QCustomMenuItem
129 {
130   public:
131         CustomItem(const QString & s, const QFont & f):string(s), font(f)
132         {
133         };
134         ~CustomItem()
135         {
136         }
137
138         void paint(QPainter * p, const QColorGroup & /*cg */ , bool /*act */ ,
139                 bool /*enabled */ , int x, int y, int w, int h)
140         {
141                 p->setFont(font);
142                 p->drawText(x, y, w, h,
143                         AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
144         }
145
146         QSize sizeHint()
147         {
148                 return QFontMetrics(font).
149                         size(AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
150         }
151   private:
152         QString string;
153         QFont font;
154 };
155
156 //=============================================================================
157 /*!
158  *
159  */
160 //=============================================================================
161 SMESHGUI::SMESHGUI():
162 QObject()
163 {
164 }
165
166 //=============================================================================
167 /*!
168  *
169  */
170 //=============================================================================
171 SMESHGUI::~SMESHGUI()
172 {
173 }
174
175 //=============================================================================
176 /*!
177  *
178  */
179 //=============================================================================
180 SMESHGUI *SMESHGUI::GetSMESHGUI()
181 {
182         return smeshGUI;
183 }
184
185 //=============================================================================
186 /*!
187  *
188  */
189 //=============================================================================
190 SMESHGUI *SMESHGUI::GetOrCreateSMESHGUI(QAD_Desktop * desktop)
191 {
192         if (smeshGUI == 0)
193         {
194                 setOrb();
195                 smeshGUI = new SMESHGUI;
196                 smeshGUI->myActiveDialogBox = 0;
197                 smeshGUI->myState = -1;
198                 smeshGUI->myDesktop = desktop;
199                 smeshGUI->myActiveStudy = desktop->getActiveStudy();
200
201                 Engines::Component_var comp =
202                         desktop->getEngine("FactoryServer", "SMESH");
203                 smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
204
205                 Engines::Component_var comp1 =
206                         desktop->getEngine("FactoryServer", "GEOM");
207                 smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
208
209                 /* GetCurrentStudy */
210                 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
211
212                 smeshGUI->myComponentGeom->GetCurrentStudy(smeshGUI->myStudyId);
213                 //    smeshGUI->myComponentGeom->NbLabels();
214
215                 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
216
217                 smeshGUI->myStudyAPI =
218                         SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
219
220                 smeshGUI->mySimulationActors = vtkActorCollection::New();
221                 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
222         }
223         else
224         {
225                 /* study may have changed */
226                 smeshGUI->myActiveStudy = desktop->getActiveStudy();
227                 smeshGUI->myStudyAPI.Update(smeshGUI->myComponentMesh);
228         }
229
230         /* Automatic Update */
231         if (desktop->menuBar()->isItemChecked(1001))
232                 smeshGUI->myAutomaticUpdate = true;
233         else
234                 smeshGUI->myAutomaticUpdate = false;
235
236         return smeshGUI;
237 }
238
239 //=============================================================================
240 /*!
241  *
242  */
243 //=============================================================================
244 void SMESHGUI::SetState(int aState)
245 {
246         this->myState = aState;
247         return;
248 }
249
250 //=============================================================================
251 /*!
252  *
253  */
254 //=============================================================================
255 void SMESHGUI::ResetState()
256 {
257         this->myState = -1;
258         return;
259 }
260
261 //=============================================================================
262 /*!
263  *
264  */
265 //=============================================================================
266 void SMESHGUI::EmitSignalDeactivateDialog()
267 {
268         emit this->SignalDeactivateActiveDialog();
269         return;
270 }
271
272 //=============================================================================
273 /*!
274  *
275  */
276 //=============================================================================
277 void SMESHGUI::EmitSignalCloseAllDialogs()
278 {
279         emit this->SignalCloseAllDialogs();
280         return;
281 }
282
283 //=============================================================================
284 /*!
285  *
286  */
287 //=============================================================================
288 QDialog *SMESHGUI::GetActiveDialogBox()
289 {
290         return this->myActiveDialogBox;
291 }
292
293 //=============================================================================
294 /*!
295  *
296  */
297 //=============================================================================
298 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
299 {
300         this->myActiveDialogBox = (QDialog *) aDlg;
301         return;
302 }
303
304 //=============================================================================
305 /*!
306  *
307  */
308 //=============================================================================
309 QAD_Study *SMESHGUI::GetActiveStudy()
310 {
311         return this->myActiveStudy;
312 }
313
314 //=============================================================================
315 /*!
316  *
317  */
318 //=============================================================================
319 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
320 {
321         return SALOMEDS::Study::_narrow(myStudy);
322 }
323
324 //=============================================================================
325 /*!
326  *
327  */
328 //=============================================================================
329 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
330 {
331         return myStudyAPI;
332 }
333
334 //=============================================================================
335 /*!
336  *
337  */
338 //=============================================================================
339 QAD_Desktop *SMESHGUI::GetDesktop()
340 {
341         return this->myDesktop;
342 }
343
344 //=============================================================================
345 /*!
346  *
347  */
348 //=============================================================================
349 vtkScalarBarActor *SMESHGUI::GetScalarBar()
350 {
351         vtkRenderer *aRenderer =
352                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
353                 getRightFrame()->getViewFrame())->getRenderer();
354         vtkActor2DCollection *actor2DList = aRenderer->GetActors2D();
355         actor2DList->InitTraversal();
356         vtkActor2D *aActor2d = actor2DList->GetNextActor2D();
357         while (aActor2d != NULL)
358         {
359                 if (aActor2d->IsA("vtkScalarBarActor"))
360                         return vtkScalarBarActor::SafeDownCast(aActor2d);
361                 actor2DList->GetNextActor2D();
362         }
363         return NULL;
364 }
365
366 //=============================================================================
367 /*!
368  *
369  */
370 //=============================================================================
371 void SMESHGUI::activeStudyChanged(QAD_Desktop * parent)
372 {
373         MESSAGE("SMESHGUI::activeStudyChanged init.")
374                 /* Create or retrieve an object SMESHGUI */
375                 SMESHGUI::GetOrCreateSMESHGUI(parent);
376         if (smeshGUI != 0)
377         {
378                 smeshGUI->EmitSignalCloseAllDialogs();
379                 MESSAGE("Active study changed : SMESHGUI nullified" << endl);
380                 smeshGUI = 0;
381         }
382
383         //smeshGUI->SetSettings( parent ); //DCQ : Pb. Multi-Etudes
384         MESSAGE("SMESHGUI::activeStudyChanged done.") return;
385 }
386
387 //=============================================================================
388 /*!
389  *
390  */
391 //=============================================================================
392 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
393 {
394         /* Here the position is on the bottom right corner - 10 */
395         aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
396         QAD_Desktop *PP = QAD_Application::getDesktop();
397         x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
398         y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
399         return true;
400 }
401
402 //=============================================================================
403 /*!
404  *
405  */
406 //=============================================================================
407 void SMESHGUI::EraseSimulationActors()
408 {
409         if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
410         {                                                       //VTK
411                 vtkRenderer *theRenderer =
412                         ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
413                         getRightFrame()->getViewFrame())->getRenderer();
414                 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
415
416                 if (mySimulationActors != NULL)
417                 {
418
419                         mySimulationActors->InitTraversal();
420                         vtkActor *ac = mySimulationActors->GetNextActor();
421                         while (!(ac == NULL))
422                         {
423                                 theRenderer->RemoveActor(ac);
424                                 ac = mySimulationActors->GetNextActor();
425                         }
426                         mySimulationActors->RemoveAllItems();
427                 }
428                 if (mySimulationActors2D != NULL)
429                 {
430                         mySimulationActors2D->InitTraversal();
431                         vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
432                         while (!(ac == NULL))
433                         {
434                                 theRenderer->RemoveActor2D(ac);
435                                 ac = mySimulationActors2D->GetNextActor2D();
436                         }
437                         mySimulationActors2D->RemoveAllItems();
438                 }
439                 renWin->Render();
440         }
441 }
442
443 //=============================================================================
444 /*!
445  *
446  */
447 //=============================================================================
448 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh(GEOM::GEOM_Shape_ptr aShape,
449         QString NameMesh)
450 {
451         try
452         {
453                 if (!myComponentMesh->_is_nil() && !aShape->_is_nil())
454                 {
455                         SMESH::SMESH_Mesh_var aMesh =
456                                 myComponentMesh->Init(myComponentGeom, myStudyId, aShape);
457
458                         if (!aMesh->_is_nil())
459                         {
460                                 SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh(aMesh);
461                                 myStudyAPI.SetName(SM, NameMesh);
462
463                                 // GEOM::GEOM_Shape has non-empty StudyShapeId only after AddInStudy operation,
464                                 // not after loading from file, so let's use more reliable way to retrieve SObject
465                                 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
466                                 SALOMEDS::SObject_var SObject =
467                                         myStudy->FindObjectIOR(ShapeIOR);
468                                 if (!SObject->_is_nil() && !SM->_is_nil())
469                                 {
470                                         myStudyAPI.SetShape(SM, SObject);
471                                 }
472                                 return SMESH::SMESH_Mesh::_narrow(aMesh);
473                         }
474                 }
475         }
476         catch(const SALOME::SALOME_Exception & S_ex)
477         {
478                 QtCatchCorbaException(S_ex);
479         }
480         myActiveStudy->updateObjBrowser(true);
481         return SMESH::SMESH_Mesh::_nil();
482 }
483
484 //=============================================================================
485 /*!
486  *
487  */
488 //=============================================================================
489 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh(SMESH::SMESH_Mesh_ptr aMesh,
490         GEOM::GEOM_Shape_ptr aShape, QString NameMesh)
491 {
492         try
493         {
494                 SMESH::SMESH_subMesh_var aSubMesh = aMesh->GetElementsOnShape(aShape);
495                 SALOMEDS::SObject_var SO_Mesh = myStudyAPI.FindMesh(aMesh);
496                 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
497                 SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectIOR(ShapeIOR);
498
499                 if (!SO_GeomShape->_is_nil() && !SO_Mesh->_is_nil() &&
500                         !aSubMesh->_is_nil() && !aMesh->_is_nil())
501                 {
502                         SALOMEDS::SObject_var SO =
503                                 myStudyAPI.AddSubMeshOnShape(SO_Mesh, SO_GeomShape, aSubMesh,
504                                 aShape->ShapeType());
505                         myStudyAPI.SetName(SO, NameMesh);
506
507                         SMESH_Actor *amesh = SMESH_Actor::New();
508                         Handle(SALOME_InteractiveObject) IO =
509                                 new SALOME_InteractiveObject(SO->GetID(), "MESH",
510                                 strdup(NameMesh));
511                         amesh->setIO(IO);
512                         amesh->setName(strdup(NameMesh));
513                         DisplayActor(amesh, false);
514                         return SMESH::SMESH_subMesh::_narrow(aSubMesh);
515                 }
516         }
517         catch(const SALOME::SALOME_Exception & S_ex)
518         {
519                 QtCatchCorbaException(S_ex);
520         }
521         myActiveStudy->updateObjBrowser(true);
522         return SMESH::SMESH_subMesh::_nil();
523 }
524
525 //=============================================================================
526 /*!
527  *
528  */
529 //=============================================================================
530 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis(QString TypeHypothesis,
531         QString NameHypothesis)
532 {
533         SMESH::SMESH_Hypothesis_var Hyp;
534         try
535         {
536                 Hyp = myComponentMesh->CreateHypothesis(TypeHypothesis, myStudyId);
537                 if (!Hyp->_is_nil())
538                 {
539                         SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewHypothesis(Hyp);
540                         myStudyAPI.SetName(SHyp, NameHypothesis);
541                 }
542         }
543         catch(const SALOME::SALOME_Exception & S_ex)
544         {
545                 QtCatchCorbaException(S_ex);
546         }
547
548         return SMESH::SMESH_Hypothesis::_narrow(Hyp);
549 }
550
551 //=============================================================================
552 /*!
553  *
554  */
555 //=============================================================================
556 void SMESHGUI::AddHypothesisOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
557         SMESH::SMESH_Hypothesis_ptr aHyp)
558 {
559         if (!aMesh->_is_nil())
560         {
561                 QApplication::setOverrideCursor(Qt::waitCursor);
562                 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
563                 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
564                 try
565                 {
566                         bool res = aMesh->AddHypothesis(aShape, aHyp);
567                         if (res)
568                         {
569                                 SALOMEDS::SObject_var SH =
570                                         myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
571                                 if (!SM->_is_nil() && !SH->_is_nil())
572                                 {
573                                         myStudyAPI.SetHypothesis(SM, SH);
574                                         myStudyAPI.ModifiedMesh(SM, false);
575                                 }
576                                 QApplication::restoreOverrideCursor();
577                         }
578                         else
579                         {
580                                 QApplication::restoreOverrideCursor();
581                                 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
582                                         tr("SMESH_WRN_WARNING"),
583                                         tr("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"),
584                                         tr("SMESH_BUT_YES"));
585                         }
586                 }
587                 catch(const SALOME::SALOME_Exception & S_ex)
588                 {
589                         QtCatchCorbaException(S_ex);
590                 }
591         }
592         myActiveStudy->updateObjBrowser(true);
593         QApplication::restoreOverrideCursor();
594 }
595
596 //=============================================================================
597 /*!
598  *
599  */
600 //=============================================================================
601 void SMESHGUI::
602 RemoveHypothesisOrAlgorithmOnMesh(const Handle(SALOME_InteractiveObject) &
603         IObject)
604 {
605         if (IObject->hasReference())
606         {
607                 SMESH::SMESH_Hypothesis_var anHyp;
608                 SALOMEDS::SObject_var SO_Hypothesis =
609                         smeshGUI->myStudy->FindObjectID(IObject->getEntry());
610                 SALOMEDS::GenericAttribute_var anAttr;
611                 SALOMEDS::AttributeIOR_var anIOR;
612
613                 if (!SO_Hypothesis->_is_nil())
614                 {
615                         QApplication::setOverrideCursor(Qt::waitCursor);
616                         if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR"))
617                         {
618                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
619                                 anHyp =
620                                         SMESH::SMESH_Hypothesis::_narrow(_orb->
621                                         string_to_object(anIOR->Value()));
622                         }
623
624                         SALOMEDS::SObject_var SO_Applied_Hypothesis =
625                                 smeshGUI->myStudy->FindObjectID(IObject->getReference());
626                         if (!SO_Applied_Hypothesis->_is_nil())
627                         {
628                                 SALOMEDS::SObject_var MorSM =
629                                         smeshGUI->myStudyAPI.
630                                         GetMeshOrSubmesh(SO_Applied_Hypothesis);
631                                 if (!MorSM->_is_nil())
632                                 {
633                                         smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
634
635                                         GEOM::GEOM_Shape_var aShape =
636                                                 smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
637                                         if (!aShape->_is_nil())
638                                         {
639                                                 if (MorSM->FindAttribute(anAttr, "AttributeIOR"))
640                                                 {
641                                                         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
642                                                         SMESH::SMESH_Mesh_var aMesh =
643                                                                 SMESH::SMESH_Mesh::_narrow(_orb->
644                                                                 string_to_object(anIOR->Value()));
645                                                         SMESH::SMESH_subMesh_var aSubMesh =
646                                                                 SMESH::SMESH_subMesh::_narrow(_orb->
647                                                                 string_to_object(anIOR->Value()));
648                                                         if (!aMesh->_is_nil())
649                                                         {
650                                                                 bool res =
651                                                                         aMesh->RemoveHypothesis(aShape, anHyp);
652                                                                 if (!res)
653                                                                 {
654                                                                         QApplication::restoreOverrideCursor();
655                                                                         QAD_MessageBox::warn1(QAD_Application::
656                                                                                 getDesktop(), tr("SMESH_WRN_WARNING"),
657                                                                                 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
658                                                                                 tr("SMESH_BUT_YES"));
659                                                                 }
660                                                         }
661                                                         else if (!aSubMesh->_is_nil())
662                                                         {
663                                                                 aMesh = aSubMesh->GetFather();
664                                                                 if (!aMesh->_is_nil())
665                                                                 {
666                                                                         bool res =
667                                                                                 aMesh->RemoveHypothesis(aShape, anHyp);
668                                                                         if (!res)
669                                                                         {
670                                                                                 QApplication::restoreOverrideCursor();
671                                                                                 QAD_MessageBox::warn1(QAD_Application::
672                                                                                         getDesktop(),
673                                                                                         tr("SMESH_WRN_WARNING"),
674                                                                                         tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
675                                                                                         tr("SMESH_BUT_YES"));
676                                                                         }
677                                                                 }
678                                                         }
679                                                         if (myAutomaticUpdate)
680                                                         {
681                                                                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
682                                                                 if (Mesh != NULL)
683                                                                 {
684 #ifdef TRACE
685                                                                         Dump(Mesh);
686 #endif
687                                                                         DisplayActor(Mesh);
688                                                                         DisplayEdges(Mesh);
689                                                                         smeshGUI->ChangeRepresentation(Mesh,
690                                                                                 Mesh->getDisplayMode());
691                                                                 }
692                                                         }
693                                                 }
694                                         }
695                                 }
696                                 smeshGUI->myStudyAPI.UnSetHypothesis(SO_Applied_Hypothesis);
697                         }
698                 }
699         }
700         else if (IObject->hasEntry())
701         {
702         MESSAGE("IObject entry " << IObject->getEntry())}
703         QApplication::restoreOverrideCursor();
704 }
705
706 //=============================================================================
707 /*!
708  *
709  */
710 //=============================================================================
711 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh(SALOMEDS::SObject_ptr MorSM,
712         SMESH::SMESH_Hypothesis_ptr anHyp)
713 {
714         SALOMEDS::SObject_var AHR, aRef;
715         SALOMEDS::GenericAttribute_var anAttr;
716         SALOMEDS::AttributeIOR_var anIOR;
717
718         if (!MorSM->_is_nil())
719         {
720                 GEOM::GEOM_Shape_var aShape =
721                         smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
722                 if (!aShape->_is_nil())
723                 {
724                         if (MorSM->FindAttribute(anAttr, "AttributeIOR"))
725                         {
726                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
727                                 SMESH::SMESH_Mesh_var aMesh =
728                                         SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
729                                                 Value()));
730                                 SMESH::SMESH_subMesh_var aSubMesh =
731                                         SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->
732                                                 Value()));
733                                 if (!aMesh->_is_nil())
734                                 {
735                                         bool res = aMesh->RemoveHypothesis(aShape, anHyp);
736                                         if (!res)
737                                         {
738                                                 QApplication::restoreOverrideCursor();
739                                                 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
740                                                         tr("SMESH_WRN_WARNING"),
741                                                         tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
742                                                         tr("SMESH_BUT_YES"));
743                                         }
744                                 }
745                                 else if (!aSubMesh->_is_nil())
746                                 {
747                                         aMesh = aSubMesh->GetFather();
748                                         if (!aMesh->_is_nil())
749                                         {
750                                                 bool res = aMesh->RemoveHypothesis(aShape, anHyp);
751                                                 if (!res)
752                                                 {
753                                                         QApplication::restoreOverrideCursor();
754                                                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
755                                                                 tr("SMESH_WRN_WARNING"),
756                                                                 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
757                                                                 tr("SMESH_BUT_YES"));
758                                                 }
759                                         }
760                                 }
761                                 if (myAutomaticUpdate)
762                                 {
763                                         SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
764                                         if (Mesh != NULL)
765                                         {
766 #ifdef TRACE
767                                                 Dump(Mesh);
768 #endif
769                                                 DisplayActor(Mesh);
770                                                 DisplayEdges(Mesh);
771                                                 // smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
772                                         }
773                                 }
774                         }
775                 }
776
777                 if (MorSM->FindSubObject(2, AHR))
778                 {
779                         SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
780                         for (; it->More(); it->Next())
781                         {
782                                 SALOMEDS::SObject_var Obj = it->Value();
783                                 if (Obj->ReferencedObject(aRef))
784                                 {
785                                         if (aRef->FindAttribute(anAttr, "AttributeIOR"))
786                                         {
787                                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
788                                                 if (strcmp(anIOR->Value(),
789                                                                 _orb->object_to_string(anHyp)) == 0)
790                                                 {
791                                                         smeshGUI->myStudyAPI.UnSetHypothesis(Obj);
792                                                         break;
793                                                 }
794                                         }
795                                 }
796                         }
797                 }
798                 if (MorSM->FindSubObject(3, AHR))
799                 {
800                         SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
801                         for (; it->More(); it->Next())
802                         {
803                                 SALOMEDS::SObject_var Obj = it->Value();
804                                 if (Obj->ReferencedObject(aRef))
805                                 {
806                                         if (aRef->FindAttribute(anAttr, "AttributeIOR"))
807                                         {
808                                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
809                                                 if (strcmp(anIOR->Value(),
810                                                                 _orb->object_to_string(anHyp)) == 0)
811                                                 {
812                                                         smeshGUI->myStudyAPI.UnSetAlgorithm(Obj);
813                                                         break;
814                                                 }
815                                         }
816                                 }
817                         }
818                 }
819                 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
820         }
821         QApplication::restoreOverrideCursor();
822 }
823
824 //=============================================================================
825 /*!
826  *
827  */
828 //=============================================================================
829 void SMESHGUI::AddAlgorithmOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
830         SMESH::SMESH_Hypothesis_ptr aHyp)
831 {
832         if (!aMesh->_is_nil())
833         {
834                 QApplication::setOverrideCursor(Qt::waitCursor);
835                 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
836                 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
837                 try
838                 {
839                         bool res = aMesh->AddHypothesis(aShape, aHyp);
840                         if (res)
841                         {
842                                 SALOMEDS::SObject_var SH =
843                                         myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
844                                 if (!SM->_is_nil() && !SH->_is_nil())
845                                 {
846                                         myStudyAPI.SetAlgorithms(SM, SH);
847                                         myStudyAPI.ModifiedMesh(SM, false);
848                                 }
849                         }
850                         else
851                         {
852                                 QApplication::restoreOverrideCursor();
853                                 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
854                                         tr("SMESH_WRN_WARNING"),
855                                         tr("SMESH_WRN_ALGORITHM_ALREADYEXIST"),
856                                         tr("SMESH_BUT_YES"));
857                         }
858                 }
859                 catch(const SALOME::SALOME_Exception & S_ex)
860                 {
861                         QtCatchCorbaException(S_ex);
862                 }
863         }
864         myActiveStudy->updateObjBrowser(true);
865         QApplication::restoreOverrideCursor();
866 }
867
868 //=============================================================================
869 /*!
870  *
871  */
872 //=============================================================================
873 void SMESHGUI::AddHypothesisOnSubMesh(SMESH::SMESH_subMesh_ptr aSubMesh,
874         SMESH::SMESH_Hypothesis_ptr aHyp)
875 {
876         if (!aSubMesh->_is_nil())
877         {
878                 QApplication::setOverrideCursor(Qt::waitCursor);
879                 try
880                 {
881                         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
882                         SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh(aSubMesh);
883                         GEOM::GEOM_Shape_var aShape =
884                                 myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
885                         if (!aMesh->_is_nil())
886                         {
887                                 bool res = aMesh->AddHypothesis(aShape, aHyp);
888                                 if (res)
889                                 {
890                                         SALOMEDS::SObject_var SH =
891                                                 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
892                                         if (!SsubM->_is_nil() && !SH->_is_nil())
893                                         {
894                                                 myStudyAPI.SetHypothesis(SsubM, SH);
895                                                 myStudyAPI.ModifiedMesh(SsubM, false);
896                                         }
897                                 }
898                                 else
899                                 {
900                                         QApplication::restoreOverrideCursor();
901                                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
902                                                 tr("SMESH_WRN_WARNING"),
903                                                 tr("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"),
904                                                 tr("SMESH_BUT_YES"));
905                                 }
906                         }
907                 }
908                 catch(const SALOME::SALOME_Exception & S_ex)
909                 {
910                         QtCatchCorbaException(S_ex);
911                 }
912         }
913         myActiveStudy->updateObjBrowser(true);
914         QApplication::restoreOverrideCursor();
915 }
916
917 //=============================================================================
918 /*!
919  *
920  */
921 //=============================================================================
922 void SMESHGUI::AddAlgorithmOnSubMesh(SMESH::SMESH_subMesh_ptr aSubMesh,
923         SMESH::SMESH_Hypothesis_ptr aHyp)
924 {
925         if (!aSubMesh->_is_nil())
926         {
927                 QApplication::setOverrideCursor(Qt::waitCursor);
928                 try
929                 {
930                         SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
931                         SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh(aSubMesh);
932                         GEOM::GEOM_Shape_var aShape =
933                                 myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
934                         if (!aMesh->_is_nil())
935                         {
936                                 bool res = aMesh->AddHypothesis(aShape, aHyp);
937                                 if (res)
938                                 {
939                                         SALOMEDS::SObject_var SH =
940                                                 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
941                                         if (!SsubM->_is_nil() && !SH->_is_nil())
942                                         {
943                                                 myStudyAPI.SetAlgorithms(SsubM, SH);
944                                                 myStudyAPI.ModifiedMesh(SsubM, false);
945                                         }
946                                 }
947                                 else
948                                 {
949                                         QApplication::restoreOverrideCursor();
950                                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
951                                                 tr("SMESH_WRN_WARNING"),
952                                                 tr("SMESH_WRN_ALGORITHM_ALREADYEXIST"),
953                                                 tr("SMESH_BUT_YES"));
954                                 }
955                         }
956                 }
957                 catch(const SALOME::SALOME_Exception & S_ex)
958                 {
959                         QtCatchCorbaException(S_ex);
960                 }
961         }
962         myActiveStudy->updateObjBrowser(true);
963         QApplication::restoreOverrideCursor();
964 }
965
966 //=============================================================================
967 /*!
968  *
969  */
970 //=============================================================================
971 void SMESHGUI::CreateAlgorithm(QString TypeAlgo, QString NameAlgo)
972 {
973         SMESH::SMESH_Hypothesis_var Hyp;
974         try
975         {
976                 if (TypeAlgo.compare("Regular_1D") == 0)
977                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
978                 else if (TypeAlgo.compare("MEFISTO_2D") == 0)
979                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
980                 else if (TypeAlgo.compare("Quadrangle_2D") == 0)
981                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
982                 else if (TypeAlgo.compare("Hexa_3D") == 0)
983                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
984                 else if (TypeAlgo.compare("NETGEN_3D") == 0)
985                         Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
986
987                 if (!Hyp->_is_nil())
988                 {
989                         SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms(Hyp);
990                         myStudyAPI.SetName(SHyp, NameAlgo);
991                 }
992         }
993         catch(const SALOME::SALOME_Exception & S_ex)
994         {
995                 QtCatchCorbaException(S_ex);
996         }
997         myActiveStudy->updateObjBrowser(true);
998 }
999
1000 //=============================================================================
1001 /*!
1002  *
1003  */
1004 //=============================================================================
1005 void SMESHGUI::CreateLocalLength(QString TypeHypothesis, QString NameHypothesis,
1006         double Length)
1007 {
1008         QApplication::setOverrideCursor(Qt::waitCursor);
1009         try
1010         {
1011                 SMESH::SMESH_Hypothesis_var Hyp =
1012                         SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1013                                 NameHypothesis));
1014                 SMESH::SMESH_LocalLength_var LL =
1015                         SMESH::SMESH_LocalLength::_narrow(Hyp);
1016                 if (!LL->_is_nil())
1017                         LL->SetLength(Length);
1018         }
1019         catch(const SALOME::SALOME_Exception & S_ex)
1020         {
1021                 QtCatchCorbaException(S_ex);
1022         }
1023         myActiveStudy->updateObjBrowser(true);
1024         QApplication::restoreOverrideCursor();
1025 }
1026
1027 //=============================================================================
1028 /*!
1029  *
1030  */
1031 //=============================================================================
1032 void SMESHGUI::CreateMaxElementArea(QString TypeHypothesis,
1033         QString NameHypothesis, double MaxArea)
1034 {
1035         QApplication::setOverrideCursor(Qt::waitCursor);
1036         try
1037         {
1038                 SMESH::SMESH_Hypothesis_var Hyp =
1039                         SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1040                                 NameHypothesis));
1041                 SMESH::SMESH_MaxElementArea_var MaxElArea =
1042                         SMESH::SMESH_MaxElementArea::_narrow(Hyp);
1043                 if (!MaxElArea->_is_nil())
1044                         MaxElArea->SetMaxElementArea(MaxArea);
1045         }
1046         catch(SALOME::SALOME_Exception & S_ex)
1047         {
1048                 QtCatchCorbaException(S_ex);
1049         }
1050
1051         myActiveStudy->updateObjBrowser(true);
1052         QApplication::restoreOverrideCursor();
1053 }
1054
1055 //=============================================================================
1056 /*!
1057  *
1058  */
1059 //=============================================================================
1060 void SMESHGUI::CreateMaxElementVolume(QString TypeHypothesis,
1061         QString NameHypothesis, double MaxVolume)
1062 {
1063         QApplication::setOverrideCursor(Qt::waitCursor);
1064         try
1065         {
1066                 SMESH::SMESH_Hypothesis_var Hyp =
1067                         SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1068                                 NameHypothesis));
1069                 SMESH::SMESH_MaxElementVolume_var MaxElVolume =
1070                         SMESH::SMESH_MaxElementVolume::_narrow(Hyp);
1071                 if (!MaxElVolume->_is_nil())
1072                         MaxElVolume->SetMaxElementVolume(MaxVolume);
1073         }
1074         catch(const SALOME::SALOME_Exception & S_ex)
1075         {
1076                 QtCatchCorbaException(S_ex);
1077         }
1078         myActiveStudy->updateObjBrowser(true);
1079         QApplication::restoreOverrideCursor();
1080 }
1081
1082 //=============================================================================
1083 /*!
1084  *
1085  */
1086 //=============================================================================
1087 void SMESHGUI::CreateNbSegments(QString TypeHypothesis, QString NameHypothesis,
1088         int nbSegments)
1089 {
1090         QApplication::setOverrideCursor(Qt::waitCursor);
1091         try
1092         {
1093                 SMESH::SMESH_Hypothesis_var Hyp =
1094                         SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1095                                 NameHypothesis));
1096                 SMESH::SMESH_NumberOfSegments_var NbS =
1097                         SMESH::SMESH_NumberOfSegments::_narrow(Hyp);
1098                 if (!NbS->_is_nil())
1099                         NbS->SetNumberOfSegments(nbSegments);
1100         }
1101         catch(const SALOME::SALOME_Exception & S_ex)
1102         {
1103                 QtCatchCorbaException(S_ex);
1104         }
1105         myActiveStudy->updateObjBrowser(true);
1106         QApplication::restoreOverrideCursor();
1107 }
1108
1109 //=============================================================================
1110 /*!
1111  *
1112  */
1113 //=============================================================================
1114 int SMESHGUI::GetNameOfSelectedIObjects(SALOME_Selection * Sel, QString & aName)
1115 {
1116         int nbSel = Sel->IObjectCount();
1117         if (nbSel == 1)
1118         {
1119                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1120                 aName = IObject->getName();
1121         }
1122         else
1123         {
1124                 aName = tr("SMESH_OBJECTS_SELECTED").arg(nbSel);
1125         }
1126         return nbSel;
1127 }
1128
1129 //=============================================================================
1130 /*!
1131  *
1132  */
1133 //=============================================================================
1134 int SMESHGUI::GetNameOfSelectedNodes(SALOME_Selection * Sel, QString & aName)
1135 {
1136         int nbNodes = 0;
1137         int nbSel = Sel->IObjectCount();
1138         if (nbSel == 1)
1139         {
1140                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1141                 if (!IObject->hasEntry())
1142                         return -1;
1143
1144                 Standard_Boolean res;
1145                 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1146                 if (!res)
1147                         return -1;
1148
1149                 TColStd_MapOfInteger MapIndex;
1150                 Sel->GetIndex(IObject, MapIndex);
1151                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1152                 aName = " ";
1153                 nbNodes = MapIndex.Extent();
1154                 for (; ite.More(); ite.Next())
1155                 {
1156                         aName =
1157                                 aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) +
1158                                 " ";
1159                 }
1160         }
1161         else
1162         {
1163                 aName = "";
1164         }
1165         return nbNodes;
1166 }
1167
1168 //=============================================================================
1169 /*!
1170  *
1171  */
1172 //=============================================================================
1173 int SMESHGUI::GetNameOfSelectedElements(SALOME_Selection * Sel, QString & aName)
1174 {
1175         int nbElements = 0;
1176         int nbSel = Sel->IObjectCount();
1177         if (nbSel == 1)
1178         {
1179                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1180                 if (!IObject->hasEntry())
1181                         return -1;
1182
1183                 Standard_Boolean res;
1184                 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1185                 if (!res)
1186                         return -1;
1187
1188                 TColStd_MapOfInteger MapIndex;
1189                 Sel->GetIndex(IObject, MapIndex);
1190                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1191                 aName = " ";
1192                 nbElements = MapIndex.Extent();
1193                 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1194                 for (; ite.More(); ite.Next())
1195                 {
1196                         int idVTK = ite.Key();
1197                         MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1198                         aName =
1199                                 aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1200                 }
1201         }
1202         else
1203         {
1204                 aName = "";
1205         }
1206         return nbElements;
1207 }
1208
1209 //=============================================================================
1210 /*!
1211  *
1212  */
1213 //=============================================================================
1214 int SMESHGUI::GetNameOfSelectedEdges(SALOME_Selection * Sel, QString & aName)
1215 {
1216         int nbElements = 0;
1217         int nbSel = Sel->IObjectCount();
1218         if (nbSel == 1)
1219         {
1220                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1221                 if (!IObject->hasEntry())
1222                         return -1;
1223
1224                 Standard_Boolean res;
1225                 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1226                 if (!res)
1227                         return -1;
1228
1229                 TColStd_MapOfInteger MapIndex;
1230                 Sel->GetIndex(IObject, MapIndex);
1231                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1232                 aName = " ";
1233                 nbElements = MapIndex.Extent();
1234                 for (; ite.More(); ite.Next())
1235                 {
1236                         aName = aName + QString("%1").arg(ite.Key()) + " ";
1237                 }
1238         }
1239         else
1240         {
1241                 aName = "";
1242         }
1243         return nbElements;
1244 }
1245
1246 //=============================================================================
1247 /*!
1248  *
1249  */
1250 //=============================================================================
1251 SMESH_Actor *SMESHGUI::FindActorByEntry(QString entry,
1252         Standard_Boolean & testResult, bool onlyInActiveView)
1253 {
1254         int nbSf = myActiveStudy->getStudyFramesCount();
1255         for (int i = 0; i < nbSf; i++)
1256         {
1257                 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
1258                 if (sf->getTypeView() == VIEW_VTK)
1259                 {
1260                         vtkRenderer *Renderer =
1261                                 ((VTKViewer_ViewFrame *) sf->getRightFrame()->getViewFrame())->
1262                                 getRenderer();
1263                         vtkActorCollection *theActors = Renderer->GetActors();
1264                         theActors->InitTraversal();
1265                         vtkActor *ac = theActors->GetNextActor();
1266                         while (!(ac == NULL))
1267                         {
1268                                 if (ac->IsA("SMESH_Actor"))
1269                                 {
1270                                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
1271                                         if (anActor->hasIO())
1272                                         {
1273                                                 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1274                                                 if (strcmp(IO->getEntry(), entry) == 0)
1275                                                 {
1276                                                         if (onlyInActiveView)
1277                                                         {
1278                                                                 if (sf == myActiveStudy->getActiveStudyFrame())
1279                                                                 {
1280                                                                         testResult = true;
1281                                                                         return anActor;
1282                                                                 }
1283                                                         }
1284                                                         else
1285                                                         {
1286                                                                 testResult = true;
1287                                                                 return anActor;
1288                                                         }
1289                                                 }
1290                                         }
1291                                 }
1292                                 ac = theActors->GetNextActor();
1293                         }
1294                 }
1295         }
1296
1297         MESSAGE(" Actor Not Found ") testResult = false;
1298         return SMESH_Actor::New();
1299 }
1300
1301 //=============================================================================
1302 /*!
1303  *
1304  */
1305 //=============================================================================
1306 SMESH_Actor *SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1307         Standard_Boolean & testResult, bool onlyInActiveView)
1308 {
1309         SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
1310         if (SM->_is_nil())
1311         {
1312                 MESSAGE(" Actor Not Found ") testResult = false;
1313                 return SMESH_Actor::New();
1314         }
1315
1316         return FindActorByEntry(SM->GetID(), testResult, onlyInActiveView);
1317 }
1318
1319 //=============================================================================
1320 /*!
1321  *
1322  */
1323 //=============================================================================
1324 SMESH::SMESH_Mesh_ptr SMESHGUI::
1325 ConvertIOinMesh(const Handle(SALOME_InteractiveObject) & IO,
1326         Standard_Boolean & testResult)
1327 {
1328         SMESH::SMESH_Mesh_var aMesh;
1329         testResult = false;
1330
1331         /* case SObject */
1332         if (IO->hasEntry())
1333         {
1334                 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1335                 SALOMEDS::GenericAttribute_var anAttr;
1336                 SALOMEDS::AttributeIOR_var anIOR;
1337                 if (!obj->_is_nil())
1338                 {
1339                         if (obj->FindAttribute(anAttr, "AttributeIOR"))
1340                         {
1341                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1342                                 aMesh =
1343                                         SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
1344                                                 Value()));
1345                                 if (!aMesh->_is_nil())
1346                                 {
1347                                         testResult = true;
1348                                         return SMESH::SMESH_Mesh::_duplicate(aMesh);
1349                                 }
1350                         }
1351                 }
1352         }
1353         return SMESH::SMESH_Mesh::_nil();
1354 }
1355
1356 //=============================================================================
1357 /*!
1358  *
1359  */
1360 //=============================================================================
1361 SMESH::SMESH_subMesh_ptr SMESHGUI::
1362 ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject) & IO,
1363         Standard_Boolean & testResult)
1364 {
1365         SMESH::SMESH_subMesh_var aSubMesh;
1366         testResult = false;
1367
1368         /* case SObject */
1369         if (IO->hasEntry())
1370         {
1371                 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1372                 SALOMEDS::GenericAttribute_var anAttr;
1373                 SALOMEDS::AttributeIOR_var anIOR;
1374                 if (!obj->_is_nil())
1375                 {
1376                         if (obj->FindAttribute(anAttr, "AttributeIOR"))
1377                         {
1378                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1379                                 aSubMesh =
1380                                         SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->
1381                                                 Value()));
1382                                 if (!aSubMesh->_is_nil())
1383                                 {
1384                                         testResult = true;
1385                                         return SMESH::SMESH_subMesh::_duplicate(aSubMesh);
1386                                 }
1387                         }
1388                 }
1389         }
1390         return SMESH::SMESH_subMesh::_nil();
1391 }
1392
1393 //=============================================================================
1394 /*!
1395  *
1396  */
1397 //=============================================================================
1398 SMESH::SMESH_Hypothesis_ptr SMESHGUI::
1399 ConvertIOinSMESHHypothesis(const Handle(SALOME_InteractiveObject) & IO,
1400         Standard_Boolean & testResult)
1401 {
1402         SMESH::SMESH_Hypothesis_var aHyp;
1403         testResult = false;
1404
1405         /* case SObject */
1406         if (IO->hasEntry())
1407         {
1408                 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1409                 SALOMEDS::GenericAttribute_var anAttr;
1410                 SALOMEDS::AttributeIOR_var anIOR;
1411                 if (!obj->_is_nil())
1412                 {
1413                         if (obj->FindAttribute(anAttr, "AttributeIOR"))
1414                         {
1415                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1416                                 aHyp =
1417                                         SMESH::SMESH_Hypothesis::_narrow(_orb->
1418                                         string_to_object(anIOR->Value()));
1419                                 if (!aHyp->_is_nil())
1420                                 {
1421                                         testResult = true;
1422                                         return SMESH::SMESH_Hypothesis::_duplicate(aHyp);
1423                                 }
1424                         }
1425                 }
1426         }
1427         return SMESH::SMESH_Hypothesis::_nil();
1428 }
1429
1430 //=============================================================================
1431 /*!
1432  *
1433  */
1434 //=============================================================================
1435 GEOM::GEOM_Shape_ptr SMESHGUI::
1436 ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject) & IO,
1437         Standard_Boolean & testResult)
1438 {
1439         GEOM::GEOM_Shape_var aShape;
1440         testResult = false;
1441
1442         /* case SObject */
1443         if (IO->hasEntry())
1444         {
1445                 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1446                 SALOMEDS::GenericAttribute_var anAttr;
1447                 SALOMEDS::AttributeIOR_var anIOR;
1448                 if (!obj->_is_nil())
1449                 {
1450                         if (obj->FindAttribute(anAttr, "AttributeIOR"))
1451                         {
1452                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1453                                 aShape = myComponentGeom->GetIORFromString(anIOR->Value());
1454                                 if (!aShape->_is_nil())
1455                                 {
1456                                         testResult = true;
1457                                         return GEOM::GEOM_Shape::_duplicate(aShape);
1458                                 }
1459                         }
1460                 }
1461         }
1462         return GEOM::GEOM_Shape::_nil();
1463 }
1464
1465 //=============================================================================
1466 /*!
1467  *
1468  */
1469 //=============================================================================
1470 void SMESHGUI::SetViewMode(int commandId)
1471 {
1472         SALOME_Selection *Sel =
1473                 SALOME_Selection::Selection(myActiveStudy->getSelection());
1474         int nbSel = Sel->IObjectCount();
1475         if (nbSel >= 1)
1476         {
1477                 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1478                 for (; It.More(); It.Next())
1479                 {
1480                         Handle(SALOME_InteractiveObject) IObject = It.Value();
1481                         if (IObject->hasEntry())
1482                         {
1483                                 Standard_Boolean res;
1484                                 SMESH_Actor *ac =
1485                                         FindActorByEntry(IObject->getEntry(), res, true);
1486                                 if (res)
1487                                 {
1488                                         switch (commandId)
1489                                         {
1490                                         case 211:
1491                                         {
1492                                                 ChangeRepresentation(ac, 0);
1493                                                 break;
1494                                         }
1495                                         case 212:
1496                                         {
1497                                                 ChangeRepresentation(ac, 1);
1498                                                 break;
1499                                         }
1500                                         case 213:
1501                                         {
1502                                                 ChangeRepresentation(ac, 2);
1503                                                 break;
1504                                         }
1505                                         case 1132:
1506                                         {
1507                                                 ChangeRepresentation(ac, 3);
1508                                                 break;
1509                                         }
1510                                         }
1511                                 }
1512                         }
1513                 }
1514                 if (commandId == 1133)
1515                 {
1516                         ChangeRepresentation(SMESH_Actor::New(), 4);
1517                 }
1518         }
1519 }
1520
1521 //=============================================================================
1522 /*!
1523  *
1524  */
1525 //=============================================================================
1526 void SMESHGUI::ChangeRepresentation(SMESH_Actor * ac, int type)
1527 {
1528         if (ac->DataSource == NULL && type != 4)
1529                 return;
1530
1531         if (type != 4)
1532         {
1533                 if (ac->getMapper() == NULL)
1534                 {
1535                         return;
1536                 }
1537         }
1538         switch (type)
1539         {
1540         case 0:
1541         {
1542                 QApplication::setOverrideCursor(Qt::waitCursor);
1543                 if (ac->getDisplayMode() == 2)
1544                 {
1545                         bool isColored = ac->getMapper()->GetScalarVisibility();        //SAL3899
1546                         vtkDataSetMapper *meshMapper =
1547                                 (vtkDataSetMapper *) (ac->getMapper());
1548                         meshMapper->SetInput(ac->DataSource);
1549                         meshMapper->SetScalarVisibility(isColored);     //SAL3899
1550                 }
1551                 ac->setDisplayMode(0);
1552                 ac->GetProperty()->SetRepresentationToWireframe();
1553                 //    ac->SetActorProperty( ac->GetProperty() );
1554                 QApplication::restoreOverrideCursor();
1555                 break;
1556         }
1557         case 1:
1558         {
1559                 QApplication::setOverrideCursor(Qt::waitCursor);
1560                 if (ac->getDisplayMode() == 2)
1561                 {
1562                         bool isColored = ac->getMapper()->GetScalarVisibility();        //SAL3899
1563                         vtkDataSetMapper *meshMapper =
1564                                 (vtkDataSetMapper *) (ac->getMapper());
1565                         meshMapper->SetInput(ac->DataSource);
1566                         meshMapper->SetScalarVisibility(isColored);     //SAL3899
1567                 }
1568                 ac->setDisplayMode(1);
1569                 ac->GetProperty()->SetRepresentationToSurface();
1570                 QApplication::restoreOverrideCursor();
1571                 //    ac->SetActorProperty( ac->GetProperty() );
1572                 break;
1573         }
1574         case 2:
1575         {
1576                 //    if (!(ac->getDisplayMode()==2)) {
1577                 //    ChangeRepresentation(ac, 1);
1578                 QApplication::setOverrideCursor(Qt::waitCursor);
1579                 ac->setDisplayMode(2);
1580                 bool isColored = ac->getMapper()->GetScalarVisibility();        //SAL3899
1581                 vtkDataSetMapper *meshMapper = (vtkDataSetMapper *) (ac->getMapper());
1582                 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1583                 shrink->SetInput(ac->DataSource);
1584                 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1585
1586                 meshMapper->SetInput(shrink->GetOutput());
1587                 meshMapper->SetScalarVisibility(isColored);     //SAL3899
1588                 ac->SetMapper(meshMapper);
1589                 QApplication::restoreOverrideCursor();
1590                 //    }
1591                 break;
1592         }
1593         case 3:
1594         {
1595                 float color[3];
1596                 float edgecolor[3];
1597                 float backfacecolor[3];
1598                 float nodecolor[3];
1599                 ac->GetColor(color[0], color[1], color[2]);
1600 //       QColor c(color[0]*255,color[1]*255,color[2]*255);
1601                 int c0 = int (color[0] * 255);
1602                 int c1 = int (color[1] * 255);
1603                 int c2 = int (color[2] * 255);
1604                 QColor c(c0, c1, c2);
1605                 ac->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
1606 //       QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1607                 c0 = int (edgecolor[0] * 255);
1608                 c1 = int (edgecolor[1] * 255);
1609                 c2 = int (edgecolor[2] * 255);
1610                 QColor e(c0, c1, c2);
1611                 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1612 //       QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1613                 c0 = int (backfacecolor[0] * 255);
1614                 c1 = int (backfacecolor[1] * 255);
1615                 c2 = int (backfacecolor[2] * 255);
1616                 QColor b(c0, c1, c2);
1617                 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1618 //       QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1619                 c0 = int (nodecolor[0] * 255);
1620                 c1 = int (nodecolor[1] * 255);
1621                 c2 = int (nodecolor[2] * 255);
1622                 QColor n(c0, c1, c2);
1623
1624                 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1625                 if (Edgewidth == 0)
1626                         Edgewidth = 1;
1627                 int intValue = ac->GetNodeSize();
1628                 float Shrink = ac->GetShrinkFactor();
1629
1630                 SMESHGUI_Preferences_ColorDlg *aDlg =
1631                         new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(),
1632                         "");
1633                 aDlg->SetColor(1, c);
1634                 aDlg->SetColor(2, e);
1635                 aDlg->SetColor(3, n);
1636                 aDlg->SetColor(4, b);
1637                 aDlg->SetIntValue(1, Edgewidth);
1638                 aDlg->SetIntValue(2, intValue);
1639                 aDlg->SetIntValue(3, int (Shrink * 100.));
1640
1641                 if (aDlg->exec())
1642                 {
1643                         QApplication::setOverrideCursor(Qt::waitCursor);
1644                         QColor color = aDlg->GetColor(1);
1645                         QColor edgecolor = aDlg->GetColor(2);
1646                         QColor nodecolor = aDlg->GetColor(3);
1647                         QColor backfacecolor = aDlg->GetColor(4);
1648                         /* actor color and backface color */
1649                         ac->GetProperty()->SetColor(float (color.red()) / 255.,
1650                                 float (color.green()) / 255., float (color.blue()) / 255.);
1651                         ac->SetColor(float (color.red()) / 255.,
1652                                 float (color.green()) / 255., float (color.blue()) / 255.);
1653                         ac->GetBackfaceProperty()->SetColor(float (backfacecolor.red()) /
1654                                 255., float (backfacecolor.green()) / 255.,
1655                                 float (backfacecolor.blue()) / 255.);
1656
1657                         /* edge color */
1658                         ac->EdgeDevice->GetProperty()->SetColor(float (edgecolor.red()) /
1659                                 255., float (edgecolor.green()) / 255.,
1660                                 float (edgecolor.blue()) / 255.);
1661                         ac->EdgeShrinkDevice->GetProperty()->SetColor(float (edgecolor.
1662                                         red()) / 255., float (edgecolor.green()) / 255.,
1663                                 float (edgecolor.blue()) / 255.);
1664                         ac->SetEdgeColor(float (edgecolor.red()) / 255.,
1665                                 float (edgecolor.green()) / 255.,
1666                                 float (edgecolor.blue()) / 255.);
1667
1668                         /* Shrink factor and size edges */
1669                         ac->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
1670                         ac->EdgeDevice->GetProperty()->SetLineWidth(aDlg->GetIntValue(1));
1671                         ac->EdgeShrinkDevice->GetProperty()->SetLineWidth(aDlg->
1672                                 GetIntValue(1));
1673
1674                         /* Nodes color and size */
1675                         ac->SetNodeColor(float (nodecolor.red()) / 255.,
1676                                 float (nodecolor.green()) / 255.,
1677                                 float (nodecolor.blue()) / 255.);
1678                         ac->SetNodeSize(aDlg->GetIntValue(2));
1679
1680                         if (ac->getDisplayMode() == 2)
1681                         {
1682                                 bool isColored = ac->getMapper()->GetScalarVisibility();        //SAL3899
1683                                 vtkDataSetMapper *meshMapper =
1684                                         (vtkDataSetMapper *) (ac->getMapper());
1685                                 meshMapper->SetInput(ac->DataSource);
1686                                 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1687                                 shrink->SetInput(meshMapper->GetInput());
1688                                 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1689
1690                                 meshMapper->SetInput(shrink->GetOutput());
1691                                 meshMapper->SetScalarVisibility(isColored);     //SAL3899
1692                                 ac->SetMapper(meshMapper);
1693                         }
1694                 }
1695                 delete aDlg;
1696                 QApplication::restoreOverrideCursor();
1697                 break;
1698         }
1699         case 4:
1700         {
1701                 EmitSignalDeactivateDialog();
1702                 SALOME_Selection *Sel =
1703                         SALOME_Selection::Selection(myActiveStudy->getSelection());
1704                 SMESHGUI_TransparencyDlg *aDlg =
1705                         new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(), "",
1706                         Sel);
1707                 break;
1708         }
1709         case 5:
1710         {
1711                 QApplication::setOverrideCursor(Qt::waitCursor);
1712                 ac->GetProperty()->SetRepresentationToPoints();
1713                 QApplication::restoreOverrideCursor();
1714                 break;
1715         }
1716         }
1717
1718         QApplication::setOverrideCursor(Qt::waitCursor);
1719         if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
1720         {                                                       //VTK
1721                 vtkRenderer *theRenderer =
1722                         ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1723                         getRightFrame()->getViewFrame())->getRenderer();
1724                 theRenderer->Render();
1725         }
1726         QApplication::restoreOverrideCursor();
1727 }
1728
1729 //=============================================================================
1730 /*!
1731  *
1732  */
1733 //=============================================================================
1734 void SMESHGUI::UpdateView()
1735 {
1736         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1737                 return;
1738
1739         vtkRenderer *theRenderer =
1740                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1741                 getRightFrame()->getViewFrame())->getRenderer();
1742         theRenderer->Render();
1743 }
1744
1745 //=============================================================================
1746 /*!
1747  *
1748  */
1749 //=============================================================================
1750 void SMESHGUI::DisplayActor(SMESH_Actor * ac, bool visibility)
1751 {
1752         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1753                 return;
1754
1755         MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1756
1757         vtkRenderer *theRenderer =
1758                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1759                 getRightFrame()->getViewFrame())->getRenderer();
1760         vtkActorCollection *theActors = theRenderer->GetActors();
1761         theActors->InitTraversal();
1762         if (theActors->IsItemPresent(ac) == 0)
1763         {
1764                 vtkProperty *prop = vtkProperty::New();
1765                 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").
1766                         toFloat() / 255.,
1767                         QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat() /
1768                         255.,
1769                         QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat() /
1770                         255.);
1771
1772                 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
1773                         toInt());
1774                 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
1775                         toInt());
1776                 ac->SetProperty(prop);
1777                 ac->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").
1778                         toFloat() / 255.,
1779                         QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat() /
1780                         255.,
1781                         QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat() /
1782                         255.);
1783
1784                 //    prop->BackfaceCullingOn();
1785                 vtkProperty *backprop = vtkProperty::New();
1786                 backprop->SetColor(QAD_CONFIG->
1787                         getSetting("SMESH:SettingsBackFaceColorRed").toFloat() / 255.,
1788                         QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").
1789                         toFloat() / 255.,
1790                         QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").
1791                         toFloat() / 255.);
1792                 ac->SetBackfaceProperty(backprop);
1793
1794                 int intValue =
1795                         QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1796                 if (intValue == 0)
1797                         intValue = 80;
1798                 ac->SetShrinkFactor(intValue / 100.);
1799
1800                 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1801                 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1802
1803                 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1804                 if (DisplayMode.compare("Wireframe") == 0)
1805                 {
1806                         ac->setDisplayMode(0);
1807                         ChangeRepresentation(ac, 0);
1808                 }
1809                 else if (DisplayMode.compare("Shading") == 0)
1810                 {
1811                         ac->setDisplayMode(1);
1812                         ChangeRepresentation(ac, 1);
1813                 }
1814                 else if (DisplayMode.compare("Shrink") == 0)
1815                 {
1816                         ac->setDisplayMode(2);
1817                         ChangeRepresentation(ac, 2);
1818                 }
1819                 theRenderer->AddActor(ac);
1820         }
1821         else
1822         {
1823                 if (ac->GetMapper())
1824                         ac->GetMapper()->Update();
1825         }
1826
1827 //  if ( visibility )
1828         ac->SetVisibility(visibility);
1829 //    ac->VisibilityOn();
1830 //  else
1831 //    ac->VisibilityOff();
1832
1833         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1834         renWin->Render();
1835 }
1836
1837 //=============================================================================
1838 /*!
1839  *
1840  */
1841 //=============================================================================
1842 void SMESHGUI::EraseActor(SMESH_Actor * ac)
1843 {
1844         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1845                 return;
1846
1847         vtkRenderer *theRenderer =
1848                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1849                 getRightFrame()->getViewFrame())->getRenderer();
1850
1851         //NRI- : 02/12/2002 : Fixed bugId 882
1852         //  ac->EdgeDevice->VisibilityOff();
1853         //  ac->EdgeShrinkDevice->VisibilityOff();
1854         //  ac->VisibilityOff();
1855         ac->SetVisibility(false);
1856
1857         theRenderer->Render();
1858 }
1859
1860 //=============================================================================
1861 /*!
1862  *
1863  */
1864 //=============================================================================
1865 bool SMESHGUI::AddActorInSelection(SMESH_Actor * ac)
1866 {
1867         SALOME_Selection *Sel =
1868                 SALOME_Selection::Selection(myActiveStudy->getSelection());
1869         Sel->ClearIObjects();
1870         if (ac->hasIO())
1871                 return Sel->AddIObject(ac->getIO());
1872         else
1873                 return -1;
1874 }
1875
1876 //=============================================================================
1877 /*!
1878  *
1879  */
1880 //=============================================================================
1881 QString SMESHGUI::CheckHomogeneousSelection()
1882 {
1883         SALOME_Selection *Sel =
1884                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
1885         /* copy the list */
1886         SALOME_ListIO List;
1887         SALOME_ListIteratorOfListIO Itinit(Sel->StoredIObjects());
1888         for (; Itinit.More(); Itinit.Next())
1889         {
1890                 List.Append(Itinit.Value());
1891         }
1892
1893         QString RefType = CheckTypeObject(Sel->firstIObject());
1894         SALOME_ListIteratorOfListIO It(List);
1895         for (; It.More(); It.Next())
1896         {
1897                 Handle(SALOME_InteractiveObject) IObject = It.Value();
1898                 QString Type = CheckTypeObject(IObject);
1899                 if (Type.compare(RefType) != 0)
1900                         return "Heterogeneous Selection";
1901         }
1902
1903         Sel->ClearIObjects();
1904         SALOME_ListIteratorOfListIO It1(List);
1905         for (; It1.More(); It1.Next())
1906         {
1907                 int res = Sel->AddIObject(It1.Value());
1908                 if (res == -1)
1909                         myActiveStudy->highlight(It1.Value(), false);
1910                 if (res == 0)
1911                         myActiveStudy->highlight(It1.Value(), true);
1912         }
1913         return RefType;
1914 }
1915
1916 //=============================================================================
1917 /*!
1918  *
1919  */
1920 //=============================================================================
1921 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject) & IO)
1922 {
1923         SALOMEDS::SObject_var sobj =
1924                 smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->
1925                 getEntry());
1926         if (!sobj->_is_nil())
1927         {
1928                 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1929                 if (strcmp(scomp->GetID(), IO->getEntry()) == 0)
1930                 {                                               // component is selected
1931                         return "Component";
1932                 }
1933         }
1934
1935         SALOME_Selection *Sel =
1936                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
1937         Sel->ClearIObjects();
1938
1939         Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter(HYPOTHESIS);
1940         Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter(ALGORITHM);
1941         Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter(MESH);
1942         Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter(SUBMESH);
1943         Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter =
1944                 new SMESH_TypeFilter(MESHorSUBMESH);
1945         Handle(SMESH_TypeFilter) aSubMeshVextexFilter =
1946                 new SMESH_TypeFilter(SUBMESH_VERTEX);
1947         Handle(SMESH_TypeFilter) aSubMeshEdgeFilter =
1948                 new SMESH_TypeFilter(SUBMESH_EDGE);
1949         Handle(SMESH_TypeFilter) aSubMeshFaceFilter =
1950                 new SMESH_TypeFilter(SUBMESH_FACE);
1951         Handle(SMESH_TypeFilter) aSubMeshSolidFilter =
1952                 new SMESH_TypeFilter(SUBMESH_SOLID);
1953         Handle(SMESH_TypeFilter) aSubMeshCompoundFilter =
1954                 new SMESH_TypeFilter(SUBMESH_COMPOUND);
1955
1956         Sel->AddFilter(aHypFilter);
1957         if (Sel->AddIObject(IO) != -1)
1958         {
1959                 Sel->ClearFilters();
1960                 return "Hypothesis";
1961         }
1962
1963         Sel->ClearFilters();
1964         Sel->AddFilter(anAlgoFilter);
1965         if (Sel->AddIObject(IO) != -1)
1966         {
1967                 Sel->ClearFilters();
1968                 return "Algorithm";
1969         }
1970
1971         Sel->ClearFilters();
1972         Sel->AddFilter(aMeshFilter);
1973         if (Sel->AddIObject(IO) != -1)
1974         {
1975                 Sel->ClearFilters();
1976                 return "Mesh";
1977         }
1978
1979         Sel->ClearFilters();
1980         Sel->AddFilter(aSubMeshFilter);
1981         if (Sel->AddIObject(IO) != -1)
1982         {
1983                 Sel->ClearFilters();
1984                 return "SubMesh";
1985         }
1986
1987         Sel->ClearFilters();
1988         Sel->AddFilter(aSubMeshVextexFilter);
1989         if (Sel->AddIObject(IO) != -1)
1990         {
1991                 Sel->ClearFilters();
1992                 return "SubMeshVertex";
1993         }
1994
1995         Sel->ClearFilters();
1996         Sel->AddFilter(aSubMeshEdgeFilter);
1997         if (Sel->AddIObject(IO) != -1)
1998         {
1999                 Sel->ClearFilters();
2000                 return "SubMeshEdge";
2001         }
2002
2003         Sel->ClearFilters();
2004         Sel->AddFilter(aSubMeshFaceFilter);
2005         if (Sel->AddIObject(IO) != -1)
2006         {
2007                 Sel->ClearFilters();
2008                 return "SubMeshFace";
2009         }
2010
2011         Sel->ClearFilters();
2012         Sel->AddFilter(aSubMeshSolidFilter);
2013         if (Sel->AddIObject(IO) != -1)
2014         {
2015                 Sel->ClearFilters();
2016                 return "SubMeshSolid";
2017         }
2018
2019         Sel->ClearFilters();
2020         Sel->AddFilter(aSubMeshCompoundFilter);
2021         if (Sel->AddIObject(IO) != -1)
2022         {
2023                 Sel->ClearFilters();
2024                 return "SubMeshCompound";
2025         }
2026
2027         Sel->ClearFilters();
2028         Sel->AddIObject(IO);
2029         return "NoType";
2030 }
2031
2032 //=============================================================================
2033 /*!
2034  *
2035  */
2036 //=============================================================================
2037 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
2038 {
2039         /* Create or retrieve an object SMESHGUI */
2040         SMESHGUI::GetOrCreateSMESHGUI(parent);
2041
2042         // NRI : Temporary added
2043         if (smeshGUI->myStudy->GetProperties()->IsLocked())
2044         {
2045                 return false;
2046         }
2047         //NRI
2048
2049         //  QAD_Viewer3d* v3d;
2050         OCCViewer_Viewer3d *v3d;
2051
2052         Handle(AIS_InteractiveContext) ic;
2053         vtkRenderer *Renderer;
2054         vtkRenderWindow *RenWin;
2055
2056         if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2057                 VIEW_OCC)
2058         {
2059                 v3d =
2060                         ((OCCViewer_ViewFrame *) smeshGUI->myActiveStudy->
2061                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2062                         getViewer();
2063                 ic = v3d->getAISContext();
2064         }
2065         else if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2066                 VIEW_VTK)
2067         {
2068                 Renderer =
2069                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2070                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2071                         getRenderer();
2072                 RenWin = Renderer->GetRenderWindow();
2073         }
2074
2075         switch (theCommandID)
2076         {
2077         case 33:                                        // DELETE
2078                 smeshGUI->OnEditDelete();
2079                 break;
2080
2081         case 113:                                       // IMPORT
2082         case 112:
2083         case 111:
2084         {
2085                 smeshGUI->Import_Document(parent, theCommandID);
2086                 break;
2087         }
2088
2089         case 122:                                       // EXPORT MED
2090         case 121:
2091         case 123:
2092         {
2093                 Export_Mesh(parent, theCommandID);
2094                 break;
2095         }
2096
2097         case 200:                                       // SCALAR BAR
2098         {
2099                 smeshGUI->DisplayScalarBar(false);
2100                 break;
2101         }
2102         case 201:
2103         {
2104                 SMESHGUI_EditScalarBarDlg *aDlg =
2105                         new SMESHGUI_EditScalarBarDlg(parent, "", false);
2106                 aDlg->show();
2107                 break;
2108         }
2109         case 202:
2110         {
2111                 smeshGUI->DisplayScalarBar(true);
2112                 break;
2113         }
2114
2115         case 1133:                                      // DISPLAY MODE : WireFrame, Surface, Shrink
2116         case 1132:
2117         case 213:
2118         case 212:
2119         case 211:
2120         {
2121                 smeshGUI->SetViewMode(theCommandID);
2122                 break;
2123         }
2124
2125         case 214:                                       // UPDATE
2126         {
2127                 smeshGUI->Update();
2128                 break;
2129         }
2130
2131         case 300:                                       // ERASE
2132         {
2133                 SALOME_Selection *Sel =
2134                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2135                         getSelection());
2136                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2137                         VIEW_VTK)
2138                 {
2139                         // VTK
2140                         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2141                         for (; It.More(); It.Next())
2142                         {
2143                                 Handle(SALOME_InteractiveObject) IOS = It.Value();
2144                                 if (IOS->hasEntry())
2145                                 {
2146                                         Standard_Boolean res;
2147                                         SMESH_Actor *ac =
2148                                                 smeshGUI->FindActorByEntry(IOS->getEntry(), res, true);
2149                                         if (res)
2150                                                 smeshGUI->EraseActor(ac);
2151                                 }
2152                         }
2153                 }
2154                 Sel->ClearIObjects();
2155                 smeshGUI->myActiveStudy->updateObjBrowser(true);
2156         }
2157
2158         case 301:                                       // DISPLAY
2159         {
2160                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2161                         VIEW_VTK)
2162                 {
2163                         // VTK
2164                         QApplication::setOverrideCursor(Qt::waitCursor);
2165                         SALOMEDS::SObject_var fatherSF =
2166                                 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->
2167                                 getActiveStudyFrame()->entry());
2168
2169                         SALOME_Selection *Sel =
2170                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2171                                 getSelection());
2172                         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2173
2174                         for (; It.More(); It.Next())
2175                         {
2176                                 Handle(SALOME_InteractiveObject) IObject = It.Value();
2177                                 if (IObject->hasEntry())
2178                                 {
2179                                         Standard_Boolean res;
2180                                         SMESH_Actor *ac =
2181                                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res,
2182                                                 false);
2183                                         if (res)
2184                                         {
2185                                                 smeshGUI->DisplayActor(ac, true);
2186                                                 smeshGUI->DisplayEdges(ac);
2187                                                 smeshGUI->ChangeRepresentation(ac,
2188                                                         ac->getDisplayMode());
2189                                         }
2190                                 }
2191                         }
2192                         QApplication::restoreOverrideCursor();
2193                 }
2194                 break;
2195         }
2196
2197         case 302:                                       // DISPLAY ONLY
2198         {
2199                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2200                         VIEW_VTK)
2201                 {
2202                         QApplication::setOverrideCursor(Qt::waitCursor);
2203                         vtkActorCollection *theActors = Renderer->GetActors();
2204                         theActors->InitTraversal();
2205                         vtkActor *ac = theActors->GetNextActor();
2206                         while (!(ac == NULL))
2207                         {
2208                                 if (ac->IsA("SMESH_Actor"))
2209                                 {
2210                                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
2211                                         if (!anActor->isHighlighted())
2212                                         {
2213                                                 //anActor->VisibilityOff();
2214                                                 //NRI- : 02/12/2002 : Fixed bugId 882
2215                                                 //      anActor->EdgeDevice->VisibilityOff();
2216                                                 //      anActor->EdgeShrinkDevice->VisibilityOff();
2217                                                 anActor->SetVisibility(false);
2218                                         }
2219                                 }
2220                                 ac = theActors->GetNextActor();
2221                         }
2222
2223                         // Display selection
2224                         SALOMEDS::SObject_var fatherSF =
2225                                 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->
2226                                 getActiveStudyFrame()->entry());
2227
2228                         SALOME_Selection *Sel =
2229                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2230                                 getSelection());
2231                         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2232
2233                         for (; It.More(); It.Next())
2234                         {
2235                                 Handle(SALOME_InteractiveObject) IObject = It.Value();
2236                                 SALOMEDS::SObject_var obj =
2237                                         smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2238
2239                                 VTKViewer_RenderWindowInteractor *myRenderInter =
2240                                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2241                                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2242                                         getRWInteractor();
2243                                 //      vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
2244
2245                                 if (myRenderInter->isInViewer(IObject))
2246                                 {
2247                                         if (IObject->hasEntry())
2248                                         {
2249                                                 Standard_Boolean res;
2250                                                 SMESH_Actor *ac =
2251                                                         smeshGUI->FindActorByEntry(IObject->getEntry(), res,
2252                                                         true);
2253                                                 if (res)
2254                                                 {
2255                                                         smeshGUI->DisplayActor(ac, true);
2256                                                         smeshGUI->DisplayEdges(ac);
2257                                                         smeshGUI->ChangeRepresentation(ac,
2258                                                                 ac->getDisplayMode());
2259                                                 }
2260                                         }
2261                                 }
2262                         }
2263                         smeshGUI->myActiveStudy->updateObjBrowser(true);
2264                         QApplication::restoreOverrideCursor();
2265                 }
2266                 break;
2267         }
2268
2269         case 400:                                       // NODES
2270         {
2271                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2272                         VIEW_VTK)
2273                 {                                               //VTK
2274                         smeshGUI->EmitSignalDeactivateDialog();
2275                         SALOME_Selection *Sel =
2276                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2277                                 getSelection());
2278                         Sel->ClearIObjects();
2279                         smeshGUI->myDesktop->SetSelectionMode(1, true);
2280                         parent->menuBar()->setItemChecked(9010, false);
2281                         parent->menuBar()->setItemChecked(9011, false);
2282                         smeshGUI->ViewNodes();
2283                         SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg(parent, "", Sel);
2284                 }
2285                 else
2286                 {
2287                         QApplication::restoreOverrideCursor();
2288                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2289                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2290                                 tr("SMESH_BUT_YES"));
2291                 }
2292                 break;
2293         }
2294
2295         case 405:                                       // MOVE NODE
2296         {
2297                 smeshGUI->myDesktop->SetSelectionMode(1, true);
2298                 SALOME_Selection *Sel =
2299                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2300                         getSelection());
2301                 SMESHGUI_MoveNodesDlg *aDlg =
2302                         new SMESHGUI_MoveNodesDlg(parent, "", Sel);
2303                 break;
2304         }
2305
2306         case 701:                                       // COMPUTE MESH 
2307         {
2308                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2309                         VIEW_VTK)
2310                 {                                               //VTK
2311                         SALOME_Selection *Sel =
2312                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2313                                 getSelection());
2314                         int nbSel = Sel->IObjectCount();
2315                         if (nbSel != 1)
2316                         {
2317                                 QApplication::restoreOverrideCursor();
2318                                 break;
2319                         }
2320
2321                         SMESH::SMESH_Mesh_var aM;
2322                         SMESH::SMESH_subMesh_var aSubM;
2323                         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2324                         if (IObject->hasEntry())
2325                         {
2326                                 SALOMEDS::SObject_var aMorSM =
2327                                         smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2328                                 SALOMEDS::GenericAttribute_var anAttr;
2329                                 SALOMEDS::AttributeIOR_var anIOR;
2330                                 if (!aMorSM->_is_nil())
2331                                 {
2332                                         if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
2333                                         {
2334                                                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2335                                                 MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : IOR = "
2336                                                         << anIOR->Value())CORBA::Object_var cobj;
2337                                                 try
2338                                                 {
2339                                                         cobj = _orb->string_to_object(anIOR->Value());
2340                                                         if (CORBA::is_nil(cobj))
2341                                                         {
2342                                                         MESSAGE
2343                                                                         ("SMESHGUI::OnGUIEvent - Compute mesh : nil object")}
2344                                                 }
2345                                                 catch(CORBA::COMM_FAILURE & ex)
2346                                                 {
2347                                                 MESSAGE
2348                                                                 ("SMESHGUI::OnGUIEvent - Compute mesh : exception (1)")}
2349                                                 aM = SMESH::SMESH_Mesh::_narrow(cobj);
2350                                                 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
2351                                                 aSubM =
2352                                                         SMESH::SMESH_subMesh::_narrow(_orb->
2353                                                         string_to_object(anIOR->Value()));
2354                                                 if (!aM->_is_nil())
2355                                                 {
2356                                                         GEOM::GEOM_Shape_var refShape =
2357                                                                 smeshGUI->myStudyAPI.
2358                                                                 GetShapeOnMeshOrSubMesh(aMorSM);
2359                                                         if (!refShape->_is_nil())
2360                                                         {
2361                                                                 bool compute =
2362                                                                         smeshGUI->myComponentMesh->
2363                                                                         IsReadyToCompute(aM, refShape);
2364                                                                 if (!compute)
2365                                                                 {
2366                                                                         QApplication::restoreOverrideCursor();
2367                                                                         QAD_MessageBox::warn1(QAD_Application::
2368                                                                                 getDesktop(), tr("SMESH_WRN_WARNING"),
2369                                                                                 tr("SMESH_WRN_MISSING_PARAMETERS"),
2370                                                                                 tr("SMESH_BUT_YES"));
2371                                                                         break;
2372                                                                 }
2373                                                                 try
2374                                                                 {
2375                                                                         smeshGUI->myComponentMesh->Compute(aM,
2376                                                                                 refShape);
2377                                                                         smeshGUI->myStudyAPI.ModifiedMesh(aMorSM,
2378                                                                                 true);
2379                                                                         // TO Do : change icon of all submeshes
2380                                                                 }
2381                                                                 catch(const SALOME::SALOME_Exception & S_ex)
2382                                                                 {
2383                                                                         QtCatchCorbaException(S_ex);
2384                                                                 }
2385                                                         }
2386                                                 }
2387                                                 else if (!aSubM->_is_nil())
2388                                                 {
2389                                                         aM = aSubM->GetFather();
2390                                                         GEOM::GEOM_Shape_var refShape =
2391                                                                 smeshGUI->myStudyAPI.
2392                                                                 GetShapeOnMeshOrSubMesh(aMorSM);
2393                                                         if (!refShape->_is_nil())
2394                                                         {
2395                                                                 bool compute =
2396                                                                         smeshGUI->myComponentMesh->
2397                                                                         IsReadyToCompute(aM, refShape);
2398                                                                 if (!compute)
2399                                                                 {
2400                                                                         QApplication::restoreOverrideCursor();
2401                                                                         QAD_MessageBox::warn1(QAD_Application::
2402                                                                                 getDesktop(), tr("SMESH_WRN_WARNING"),
2403                                                                                 tr("SMESH_WRN_MISSING_PARAMETERS"),
2404                                                                                 tr("SMESH_BUT_YES"));
2405                                                                         break;
2406                                                                 }
2407                                                                 try
2408                                                                 {
2409                                                                         smeshGUI->myComponentMesh->Compute(aM,
2410                                                                                 refShape);
2411                                                                         smeshGUI->myStudyAPI.ModifiedMesh(aMorSM,
2412                                                                                 true);
2413                                                                         // TO Do : change icon of all submeshes
2414                                                                 }
2415                                                                 catch(const SALOME::SALOME_Exception & S_ex)
2416                                                                 {
2417                                                                         QtCatchCorbaException(S_ex);
2418                                                                 }
2419                                                         }
2420                                                 }
2421                                         }
2422                                 }
2423                         }
2424
2425                         // Check whether the actor for the mesh exists at least in one view
2426                         Standard_Boolean res;
2427                         SMESH_Actor *ac =
2428                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2429                         if (!res)
2430                                 smeshGUI->InitActor(aM);
2431                         else
2432                         {
2433                                 // Check whether the actor belongs to the active view
2434                                 VTKViewer_RenderWindowInteractor *rwInter =
2435                                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2436                                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2437                                         getRWInteractor();
2438
2439                                 // The actor belongs to inactive view -> create a copy and add it in the active view
2440                                 if (!rwInter->isInViewer(IObject))
2441                                 {
2442                                         SMESH_Actor *acCopy = SMESH_Actor::New();
2443                                         acCopy->ShallowCopy(ac);
2444
2445                                         smeshGUI->DisplayActor(acCopy, false);
2446                                 }
2447                         }
2448
2449                         if (smeshGUI->myAutomaticUpdate)
2450                         {
2451                                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aM);
2452                                 if (Mesh != NULL)
2453                                 {
2454 #ifdef TRACE
2455                                         Dump(Mesh);
2456 #endif
2457                                         smeshGUI->DisplayActor(Mesh, true);
2458                                         smeshGUI->DisplayEdges(Mesh, true);
2459                                         smeshGUI->ChangeRepresentation(Mesh,
2460                                                 Mesh->getDisplayMode());
2461                                 }
2462                         }
2463                 }
2464                 else
2465                 {
2466                         QApplication::restoreOverrideCursor();
2467                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2468                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2469                                 tr("SMESH_BUT_YES"));
2470                 }
2471                 QApplication::restoreOverrideCursor();
2472                 break;
2473         }
2474
2475         case 702:                                       // ADD SUB MESH 
2476         {
2477                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2478                         VIEW_VTK)
2479                 {                                               //VTK
2480                         smeshGUI->EmitSignalDeactivateDialog();
2481                         SALOME_Selection *Sel =
2482                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2483                                 getSelection());
2484                         SMESHGUI_AddSubMeshDlg *aDlg =
2485                                 new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
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                 break;
2495         }
2496
2497         case 703:                                       // INIT MESH 
2498         {
2499                 smeshGUI->EmitSignalDeactivateDialog();
2500                 SALOME_Selection *Sel =
2501                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2502                         getSelection());
2503                 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg(parent, "", Sel);
2504                 break;
2505         }
2506
2507         case 704:                                       // EDIT Hypothesis 
2508         {
2509                 smeshGUI->EmitSignalDeactivateDialog();
2510                 SALOME_Selection *Sel =
2511                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2512                         getSelection());
2513                 SMESHGUI_EditHypothesesDlg *aDlg =
2514                         new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2515                 break;
2516         }
2517
2518         case 705:                                       //  EDIT Global Hypothesis
2519         {
2520                 smeshGUI->EmitSignalDeactivateDialog();
2521                 SALOME_Selection *Sel =
2522                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2523                         getSelection());
2524                 SMESHGUI_EditHypothesesDlg *aDlg =
2525                         new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2526                 break;
2527         }
2528
2529         case 706:                                       //  EDIT Local Hypothesis
2530         {
2531                 smeshGUI->EmitSignalDeactivateDialog();
2532                 SALOME_Selection *Sel =
2533                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2534                         getSelection());
2535                 SMESHGUI_EditHypothesesDlg *aDlg =
2536                         new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2537                 break;
2538         }
2539
2540         case 806:                                       // ORIENTATION ELEMENTS
2541         {
2542                 smeshGUI->EmitSignalDeactivateDialog();
2543                 SALOME_Selection *Sel =
2544                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2545                         getSelection());
2546                 smeshGUI->myDesktop->SetSelectionMode(3, true);
2547                 SMESHGUI_OrientationElementsDlg *aDlg =
2548                         new SMESHGUI_OrientationElementsDlg(parent, "", Sel);
2549                 break;
2550         }
2551
2552         case 807:                                       // DIAGONAL INVERSION
2553         {
2554                 smeshGUI->EmitSignalDeactivateDialog();
2555                 SALOME_Selection *Sel =
2556                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2557                         getSelection());
2558                 Sel->ClearIObjects();
2559                 smeshGUI->myDesktop->SetSelectionMode(2, true);
2560                 SMESHGUI_DiagonalInversionDlg *aDlg =
2561                         new SMESHGUI_DiagonalInversionDlg(parent, "", Sel);
2562                 break;
2563         }
2564
2565         case 900:                                       // MESH INFOS
2566         {
2567                 smeshGUI->EmitSignalDeactivateDialog();
2568                 SALOME_Selection *Sel =
2569                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2570                         getSelection());
2571                 SMESHGUI_MeshInfosDlg *aDlg =
2572                         new SMESHGUI_MeshInfosDlg(parent, "", Sel);
2573                 break;
2574         }
2575
2576         case 1001:                                      // AUTOMATIC UPDATE PREFERENCES
2577         {
2578                 parent->menuBar()->setItemChecked(1001,
2579                         !parent->menuBar()->isItemChecked(1001));
2580                 if (parent->menuBar()->isItemChecked(1001))
2581                 {
2582                         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
2583                         smeshGUI->myAutomaticUpdate = true;
2584                 }
2585                 else
2586                 {
2587                         QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
2588                         smeshGUI->myAutomaticUpdate = false;
2589                 }
2590                 break;
2591         }
2592
2593         case 1003:                                      // MESH PREFERENCES
2594         {
2595                 smeshGUI->SetDisplaySettings();
2596                 break;
2597         }
2598
2599         case 1005:
2600         {
2601                 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2602                 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2603                 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2604                 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2605                 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2606                 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2607                 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2608                 int NumberOfLabels =
2609                         QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2610                 int NumberOfColors =
2611                         QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2612
2613                 if (Width == 0)
2614                         Width = 0.17;
2615                 if (Height == 0)
2616                         Height = 0.8;
2617                 if (NumberOfLabels == 0)
2618                         NumberOfLabels = 5;
2619                 if (NumberOfColors == 0)
2620                         NumberOfColors = 64;
2621
2622                 SMESHGUI_Preferences_ScalarBarDlg *aDlg =
2623                         new SMESHGUI_Preferences_ScalarBarDlg(parent, "", true);
2624
2625                 if (Bold.compare("true") == 0)
2626                         aDlg->Bold->setChecked(true);
2627                 else
2628                         aDlg->Bold->setChecked(false);
2629                 if (Italic.compare("true") == 0)
2630                         aDlg->Italic->setChecked(true);
2631                 else
2632                         aDlg->Italic->setChecked(false);
2633                 if (Shadow.compare("true") == 0)
2634                         aDlg->Shadow->setChecked(true);
2635                 else
2636                         aDlg->Shadow->setChecked(false);
2637
2638                 if (Orientation.compare("Horizontal") == 0)
2639                         aDlg->RadioHoriz->setChecked(true);
2640                 else
2641                         aDlg->RadioVert->setChecked(true);
2642
2643                 int NbItems = aDlg->ComboBox1->count();
2644                 int i = 0;
2645                 aDlg->ComboBox1->setCurrentItem(i);
2646                 while (i < NbItems)
2647                 {
2648                         if (FontFamily.compare(aDlg->ComboBox1->text(i)) == 0)
2649                                 aDlg->ComboBox1->setCurrentItem(i);
2650                         i++;
2651                 }
2652
2653                 aDlg->LineEditWidth->setText(QString("%1").arg(Width));
2654                 aDlg->LineEditHeight->setText(QString("%1").arg(Height));
2655
2656                 aDlg->SpinBoxLabels->setValue(NumberOfLabels);
2657                 aDlg->SpinBoxColors->setValue(NumberOfColors);
2658
2659                 aDlg->show();
2660                 if (aDlg->result())
2661                 {
2662                         if (aDlg->RadioHoriz->isChecked())
2663                                 Orientation = "Horizontal";
2664                         else
2665                                 Orientation = "Vertical";
2666                         if (aDlg->Bold->isChecked())
2667                                 Bold = "true";
2668                         else
2669                                 Bold = "false";
2670                         if (aDlg->Italic->isChecked())
2671                                 Italic = "true";
2672                         else
2673                                 Italic = "false";
2674                         if (aDlg->Shadow->isChecked())
2675                                 Shadow = "true";
2676                         else
2677                                 Shadow = "false";
2678
2679                         FontFamily = aDlg->ComboBox1->currentText();
2680                         Width = aDlg->LineEditWidth->text().toFloat();
2681                         Height = aDlg->LineEditHeight->text().toFloat();
2682                         NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2683                         NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2684
2685                         vtkScalarBarActor *aScalarBar = smeshGUI->GetScalarBar();
2686                         if (aScalarBar != NULL)
2687                         {
2688                                 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2689                                         FontFamily, Orientation,
2690                                         Width, Height, NumberOfColors, NumberOfLabels);
2691                         }
2692
2693                         QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2694                         QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2695                         QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2696                         QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2697                         QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2698                         QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2699                         QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2700                         QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2701                         QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2702                 }
2703                 break;
2704         }
2705
2706         case 1100:                                      // EDIT HYPOTHESIS
2707         {
2708                 SALOME_Selection *Sel =
2709                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2710                         getSelection());
2711                 int nbSel = Sel->IObjectCount();
2712
2713                 if (nbSel == 1)
2714                 {
2715                         Standard_Boolean res;
2716                         SMESH::SMESH_Hypothesis_var Hyp =
2717                                 smeshGUI->ConvertIOinSMESHHypothesis(Sel->firstIObject(), res);
2718
2719                         /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2720                         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2721                         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2722                         SALOMEDS::Study::ListOfSObject_var listSOmesh =
2723                                 smeshGUI->GetMeshesUsingAlgoOrHypothesis(Hyp);
2724
2725                         if (res)
2726                         {
2727                                 QString Name = Hyp->GetName();
2728
2729                                 if (Name.compare("LocalLength") == 0)
2730                                 {
2731                                         SMESH::SMESH_LocalLength_var LL =
2732                                                 SMESH::SMESH_LocalLength::_narrow(Hyp);
2733                                         double beforeLength = LL->GetLength();
2734                                         double Length = smeshGUI->Parameter(res,
2735                                                 beforeLength,
2736                                                 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2737                                                 tr("SMESH_VALUE"),
2738                                                 1.0E-5, 1E6, 6);
2739                                         if (res && Length != beforeLength)
2740                                         {
2741                                                 LL->SetLength(Length);
2742                                                 for (int i = 0; i < listSOmesh->length(); i++)
2743                                                 {
2744                                                         smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2745                                                                 false);
2746                                                 }
2747                                                 break;
2748                                         }
2749
2750                                 }
2751                                 else if (Name.compare("NumberOfSegments") == 0)
2752                                 {
2753                                         SMESH::SMESH_NumberOfSegments_var NOS =
2754                                                 SMESH::SMESH_NumberOfSegments::_narrow(Hyp);
2755                                         int beforeNbSeg = NOS->GetNumberOfSegments();
2756                                         int NbSeg = smeshGUI->Parameter(res,
2757                                                 beforeNbSeg,
2758                                                 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2759                                                 tr("SMESH_VALUE"),
2760                                                 1, 1000000);
2761
2762                                         if (res && NbSeg != beforeNbSeg)
2763                                         {
2764                                                 NOS->SetNumberOfSegments(NbSeg);
2765                                                 for (int i = 0; i < listSOmesh->length(); i++)
2766                                                 {
2767                                                         SALOMEDS::SObject_var SO = listSOmesh[i];
2768                                                         smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2769                                                                 false);
2770                                                 }
2771                                                 break;
2772                                         }
2773
2774                                 }
2775                                 else if (Name.compare("MaxElementArea") == 0)
2776                                 {
2777                                         SMESH::SMESH_MaxElementArea_var MEA =
2778                                                 SMESH::SMESH_MaxElementArea::_narrow(Hyp);
2779                                         double beforeMaxArea = MEA->GetMaxElementArea();
2780                                         double MaxArea = smeshGUI->Parameter(res,
2781                                                 beforeMaxArea,
2782                                                 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2783                                                 tr("SMESH_VALUE"),
2784                                                 1.0E-5, 1E6, 6);
2785                                         if (res && MaxArea != beforeMaxArea)
2786                                         {
2787                                                 MEA->SetMaxElementArea(MaxArea);
2788                                                 for (int i = 0; i < listSOmesh->length(); i++)
2789                                                 {
2790                                                         smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2791                                                                 false);
2792                                                 }
2793                                                 break;
2794                                         }
2795
2796                                 }
2797                                 else if (Name.compare("MaxElementVolume") == 0)
2798                                 {
2799                                         SMESH::SMESH_MaxElementVolume_var MEV =
2800                                                 SMESH::SMESH_MaxElementVolume::_narrow(Hyp);
2801                                         double beforeMaxVolume = MEV->GetMaxElementVolume();
2802                                         double MaxVolume = smeshGUI->Parameter(res,
2803                                                 beforeMaxVolume,
2804                                                 tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"),
2805                                                 tr("SMESH_VALUE"),
2806                                                 1.0E-5, 1E6, 6);
2807                                         if (res && MaxVolume != beforeMaxVolume)
2808                                         {
2809                                                 MEV->SetMaxElementVolume(MaxVolume);
2810                                                 for (int i = 0; i < listSOmesh->length(); i++)
2811                                                 {
2812                                                         smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2813                                                                 false);
2814                                                 }
2815                                                 break;
2816                                         }
2817
2818                                 }
2819                                 else if (Name.compare("Regular_1D") == 0)
2820                                 {
2821                                 }
2822                                 else if (Name.compare("MEFISTO_2D") == 0)
2823                                 {
2824                                 }
2825                                 else
2826                                 {
2827                                 }
2828
2829                         }
2830                 }
2831                 break;
2832         }
2833
2834         case 1101:                                      // RENAME
2835         {
2836                 SALOME_Selection *Sel =
2837                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2838                         getSelection());
2839                 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2840                 for (; It.More(); It.Next())
2841                 {
2842                         Handle(SALOME_InteractiveObject) IObject = It.Value();
2843
2844                         SALOMEDS::SObject_var obj =
2845                                 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2846                         SALOMEDS::GenericAttribute_var anAttr;
2847                         SALOMEDS::AttributeName_var aName;
2848                         if (!obj->_is_nil())
2849                         {
2850                                 if (obj->FindAttribute(anAttr, "AttributeName"))
2851                                 {
2852                                         aName = SALOMEDS::AttributeName::_narrow(anAttr);
2853                                         QString newName = QString(aName->Value());
2854                                         newName =
2855                                                 SALOMEGUI_NameDlg::getName(QAD_Application::
2856                                                 getDesktop(), newName);
2857                                         if (!newName.isEmpty())
2858                                         {
2859                                                 QApplication::setOverrideCursor(Qt::waitCursor);
2860                                                 smeshGUI->myActiveStudy->renameIObject(IObject,
2861                                                         newName);
2862                                         }
2863                                         QApplication::restoreOverrideCursor();
2864                                 }
2865                         }
2866                 }
2867                 break;
2868         }
2869
2870         case 1102:                                      // REMOVE HYPOTHESIS / ALGORITHMS
2871         {
2872                 QApplication::setOverrideCursor(Qt::waitCursor);
2873                 SALOME_Selection *Sel =
2874                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2875                         getSelection());
2876                 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2877                 for (int i = 0; It.More(); It.Next(), i++)
2878                 {
2879                         Handle(SALOME_InteractiveObject) IObject = It.Value();
2880                         smeshGUI->RemoveHypothesisOrAlgorithmOnMesh(IObject);
2881                 }
2882                 Sel->ClearIObjects();
2883                 smeshGUI->myActiveStudy->updateObjBrowser(true);
2884                 QApplication::restoreOverrideCursor();
2885                 break;
2886         }
2887
2888         case 401:                                       // GEOM::EDGE
2889         {
2890                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2891                         VIEW_VTK)
2892                 {                                               //VTK
2893                         smeshGUI->EmitSignalDeactivateDialog();
2894                         SALOME_Selection *Sel =
2895                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2896                                 getSelection());
2897                         Sel->ClearIObjects();
2898                         smeshGUI->myDesktop->SetSelectionMode(1, true);
2899                         parent->menuBar()->setItemChecked(9010, false);
2900                         parent->menuBar()->setItemChecked(9011, false);
2901                         smeshGUI->ViewNodes();
2902                         SMESHGUI_AddEdgeDlg *aDlg =
2903                                 new SMESHGUI_AddEdgeDlg(parent, "", Sel);
2904                 }
2905                 else
2906                 {
2907                         QApplication::restoreOverrideCursor();
2908                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2909                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2910                                 tr("SMESH_BUT_YES"));
2911                 }
2912                 break;
2913         }
2914         case 4021:                                      // TRIANGLE
2915         {
2916                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2917                         VIEW_VTK)
2918                 {                                               //VTK
2919                         smeshGUI->EmitSignalDeactivateDialog();
2920                         SALOME_Selection *Sel =
2921                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2922                                 getSelection());
2923                         Sel->ClearIObjects();
2924                         smeshGUI->myDesktop->SetSelectionMode(1, true);
2925                         parent->menuBar()->setItemChecked(9010, false);
2926                         parent->menuBar()->setItemChecked(9011, false);
2927                         smeshGUI->ViewNodes();
2928                         SMESHGUI_AddFaceDlg *aDlg =
2929                                 new SMESHGUI_AddFaceDlg(parent, "", Sel, 3);
2930                 }
2931                 else
2932                 {
2933                         QApplication::restoreOverrideCursor();
2934                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2935                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2936                                 tr("SMESH_BUT_YES"));
2937                 }
2938                 break;
2939         }
2940         case 4022:                                      // QUAD
2941         {
2942                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2943                         VIEW_VTK)
2944                 {                                               //VTK
2945                         smeshGUI->EmitSignalDeactivateDialog();
2946                         SALOME_Selection *Sel =
2947                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2948                                 getSelection());
2949                         Sel->ClearIObjects();
2950                         smeshGUI->myDesktop->SetSelectionMode(1, true);
2951                         parent->menuBar()->setItemChecked(9010, false);
2952                         parent->menuBar()->setItemChecked(9011, false);
2953                         smeshGUI->ViewNodes();
2954                         SMESHGUI_AddFaceDlg *aDlg =
2955                                 new SMESHGUI_AddFaceDlg(parent, "", Sel, 4);
2956                 }
2957                 else
2958                 {
2959                         QApplication::restoreOverrideCursor();
2960                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2961                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2962                                 tr("SMESH_BUT_YES"));
2963                 }
2964                 break;
2965         }
2966         case 4031:                                      // TETRA
2967         {
2968                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2969                         VIEW_VTK)
2970                 {                                               //VTK
2971                         smeshGUI->EmitSignalDeactivateDialog();
2972                         SALOME_Selection *Sel =
2973                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2974                                 getSelection());
2975                         Sel->ClearIObjects();
2976                         smeshGUI->myDesktop->SetSelectionMode(1, true);
2977                         parent->menuBar()->setItemChecked(9010, false);
2978                         parent->menuBar()->setItemChecked(9011, false);
2979                         smeshGUI->ViewNodes();
2980                         SMESHGUI_AddVolumeDlg *aDlg =
2981                                 new SMESHGUI_AddVolumeDlg(parent, "", Sel, 4);
2982                 }
2983                 else
2984                 {
2985                         QApplication::restoreOverrideCursor();
2986                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2987                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2988                                 tr("SMESH_BUT_YES"));
2989                 }
2990                 break;
2991         }
2992         case 4032:                                      // HEXA
2993         {
2994                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2995                         VIEW_VTK)
2996                 {                                               //VTK
2997                         smeshGUI->EmitSignalDeactivateDialog();
2998                         SALOME_Selection *Sel =
2999                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3000                                 getSelection());
3001                         Sel->ClearIObjects();
3002                         smeshGUI->myDesktop->SetSelectionMode(1, true);
3003                         parent->menuBar()->setItemChecked(9010, false);
3004                         parent->menuBar()->setItemChecked(9011, false);
3005                         smeshGUI->ViewNodes();
3006                         SMESHGUI_AddVolumeDlg *aDlg =
3007                                 new SMESHGUI_AddVolumeDlg(parent, "", Sel, 8);
3008                 }
3009                 else
3010                 {
3011                         QApplication::restoreOverrideCursor();
3012                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3013                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3014                                 tr("SMESH_BUT_YES"));
3015                 }
3016                 break;
3017         }
3018
3019         case 4041:                                      // REMOVES NODES
3020         {
3021                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3022                         VIEW_VTK)
3023                 {                                               //VTK
3024                         smeshGUI->EmitSignalDeactivateDialog();
3025                         SALOME_Selection *Sel =
3026                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3027                                 getSelection());
3028                         Sel->ClearIObjects();
3029                         smeshGUI->myDesktop->SetSelectionMode(1, true);
3030                         parent->menuBar()->setItemChecked(9010, false);
3031                         parent->menuBar()->setItemChecked(9011, false);
3032                         smeshGUI->ViewNodes();
3033                         SMESHGUI_RemoveNodesDlg *aDlg =
3034                                 new SMESHGUI_RemoveNodesDlg(parent, "", Sel);
3035                 }
3036                 else
3037                 {
3038                         QApplication::restoreOverrideCursor();
3039                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3040                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3041                                 tr("SMESH_BUT_YES"));
3042                 }
3043                 break;
3044         }
3045         case 4042:                                      // REMOVES ELEMENTS
3046         {
3047                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3048                         VIEW_VTK)
3049                 {                                               //VTK
3050                         smeshGUI->EmitSignalDeactivateDialog();
3051                         SALOME_Selection *Sel =
3052                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3053                                 getSelection());
3054                         Sel->ClearIObjects();
3055                         smeshGUI->myDesktop->SetSelectionMode(3, true);
3056                         SMESHGUI_RemoveElementsDlg *aDlg =
3057                                 new SMESHGUI_RemoveElementsDlg(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
3069         case 5000:                                      // HYPOTHESIS - ALGO
3070         {
3071                 smeshGUI->CreateAlgorithm("Regular_1D", "Wire Discretisation");
3072                 break;
3073         }
3074         case 5010:
3075         {
3076                 smeshGUI->CreateAlgorithm("MEFISTO_2D", "Triangle (Mefisto)");
3077                 break;
3078         }
3079         case 5011:
3080         {
3081                 smeshGUI->CreateAlgorithm("Quadrangle_2D", "Quadrangle (Mapping)");
3082                 break;
3083         }
3084         case 5020:
3085         {
3086                 smeshGUI->CreateAlgorithm("Hexa_3D", "Hexahedron (i,j,k)");
3087                 break;
3088         }
3089         case 5021:
3090         {
3091                 smeshGUI->CreateAlgorithm("NETGEN_3D", "Tetrahedron (Netgen)");
3092                 break;
3093         }
3094
3095         case 5030:                                      // HYPOTHESIS - LOCAL LENGTH
3096         {
3097                 smeshGUI->EmitSignalDeactivateDialog();
3098                 SALOME_Selection *Sel =
3099                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3100                         getSelection());
3101                 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg(parent, "");
3102                 break;
3103         }
3104         case 5031:                                      // HYPOTHESIS - NB SEGMENTS
3105         {
3106                 smeshGUI->EmitSignalDeactivateDialog();
3107                 SALOME_Selection *Sel =
3108                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3109                         getSelection());
3110                 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg(parent, "");
3111                 break;
3112         }
3113
3114         case 5032:                                      // HYPOTHESIS - MAX ELEMENT AREA
3115         {
3116                 smeshGUI->EmitSignalDeactivateDialog();
3117                 SALOME_Selection *Sel =
3118                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3119                         getSelection());
3120                 SMESHGUI_MaxElementAreaDlg *aDlg =
3121                         new SMESHGUI_MaxElementAreaDlg(parent, "");
3122                 break;
3123         }
3124
3125         case 5033:                                      // HYPOTHESIS - MAX ELEMENT VOLUME
3126         {
3127                 smeshGUI->EmitSignalDeactivateDialog();
3128                 SALOME_Selection *Sel =
3129                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3130                         getSelection());
3131                 SMESHGUI_MaxElementVolumeDlg *aDlg =
3132                         new SMESHGUI_MaxElementVolumeDlg(parent, "");
3133                 break;
3134         }
3135
3136         case 5034:                                     // HYPOTHESIS - LENGTH FROM EDGES
3137         {
3138           SMESH::SMESH_Hypothesis_var Hyp;
3139           try
3140             {
3141               Hyp = smeshGUI->myComponentMesh->CreateHypothesis("LengthFromEdges", smeshGUI->myStudyId);
3142
3143               if (!Hyp->_is_nil())
3144                 {
3145                   SALOMEDS::SObject_var SHyp = smeshGUI->myStudyAPI.AddNewHypothesis(Hyp);
3146                   smeshGUI->myStudyAPI.SetName(SHyp, "LengthFromEdges");
3147                 }
3148             }
3149           catch(const SALOME::SALOME_Exception & S_ex)
3150             {
3151               QtCatchCorbaException(S_ex);
3152             }
3153           smeshGUI->myActiveStudy->updateObjBrowser(true);
3154
3155           break;
3156         }
3157
3158         case 6016:                                      // CONTROLS 
3159         case 6015:
3160         case 6014:
3161         case 6013:
3162         case 6012:
3163         case 6011:
3164         case 6001:
3165         {
3166                 SALOME_Selection *Sel =
3167                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3168                         getSelection());
3169                 int nbSel = Sel->IObjectCount();
3170                 if (nbSel != 1)
3171                         break;
3172                 smeshGUI->Control(theCommandID);
3173                 break;
3174         }
3175
3176         case 6002:
3177         {
3178                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3179                         VIEW_VTK)
3180                 {                                               //VTK
3181                         SALOME_Selection *Sel =
3182                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3183                                 getSelection());
3184                         SMESHGUI_EdgesConnectivityDlg *Dlg =
3185                                 new SMESHGUI_EdgesConnectivityDlg(parent, "", Sel);
3186                 }
3187                 else
3188                 {
3189                         QApplication::restoreOverrideCursor();
3190                         QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3191                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3192                                 tr("SMESH_BUT_YES"));
3193                 }
3194                 break;
3195         }
3196
3197         case 9010:
3198         {
3199                 if (!parent->menuBar()->isItemChecked(9010))
3200                 {
3201                         QApplication::setOverrideCursor(Qt::waitCursor);
3202                         parent->menuBar()->setItemChecked(9011, false);
3203
3204                         smeshGUI->EraseSimulationActors();
3205                         smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
3206
3207                         SALOME_Selection *Sel =
3208                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3209                                 getSelection());
3210                         int nbSel = Sel->IObjectCount();
3211                         if (nbSel == 1)
3212                         {
3213                                 Standard_Boolean res;
3214                                 SMESH_Actor *MeshActor =
3215                                         smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(),
3216                                         res, true);
3217                                 if (res)
3218                                 {
3219                                         parent->menuBar()->setItemChecked(9010,
3220                                                 !parent->menuBar()->isItemChecked(9010));
3221
3222                                         // It's necessary to display SMDS IDs instead of VTK ones, so 
3223                                         // vtkIdFilter is unacceptable here. We have to do it manually :(
3224                                         vtkUnstructuredGrid *ptGrid = vtkUnstructuredGrid::New();
3225                                         ptGrid->CopyStructure(MeshActor->DataSource);
3226
3227                                         int numPts = MeshActor->DataSource->GetNumberOfPoints();
3228
3229                                         // Loop over points and generate ids
3230                                         vtkIntArray *ptIds = vtkIntArray::New();
3231                                         ptIds->SetNumberOfValues(numPts);
3232
3233                                         for (int id = 0; id < numPts; id++)
3234                                         {
3235                                                 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
3236                                                 ptIds->SetValue(id, idSMDS);
3237                                         }
3238
3239 // mpv porting vtk4.2.2
3240                                         //          vtkScalars* newScalars = vtkScalars::New();
3241                                         //          newScalars->SetData(ptIds);
3242                                         //          ptGrid->GetPointData()->SetScalars(newScalars);
3243                                         ptGrid->GetPointData()->SetScalars(ptIds);
3244                                         //          newScalars->Delete();
3245 // mpv
3246                                         ptIds->Delete();
3247
3248                                         vtkMaskPoints *mask = vtkMaskPoints::New();
3249                                         mask->SetInput(ptGrid);
3250                                         mask->SetOnRatio(1);
3251                                         //        mask->SetMaximumNumberOfPoints( 50 );
3252                                         //        mask->RandomModeOn();
3253
3254                                         vtkSelectVisiblePoints *visPts =
3255                                                 vtkSelectVisiblePoints::New();
3256                                         visPts->SetInput(mask->GetOutput());
3257                                         visPts->SetRenderer(((VTKViewer_ViewFrame *) smeshGUI->
3258                                                         myActiveStudy->getActiveStudyFrame()->
3259                                                         getRightFrame()->getViewFrame())->getRenderer());
3260                                         //visPts->SetSelectInvisible(1);
3261                                         visPts->SelectInvisibleOff();
3262                                         visPts->SetTolerance(0.1);
3263
3264                                         vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
3265                                         ldm->SetInput(visPts->GetOutput());
3266                                         ldm->SetLabelFormat("%g");
3267                                         ldm->SetLabelModeToLabelScalars();
3268                                         //ldm->SetLabelModeToLabelFieldData();
3269
3270                                         ldm->SetFontFamilyToTimes();
3271                                         ldm->SetFontSize(6 * parent->font().pointSize() / 5);
3272                                         ldm->SetBold(1);
3273                                         ldm->SetItalic(0);
3274                                         ldm->SetShadow(0);
3275
3276                                         vtkActor2D *pointLabels = vtkActor2D::New();
3277                                         pointLabels->SetMapper(ldm);
3278                                         pointLabels->GetProperty()->SetColor(0, 1, 0);
3279
3280                                         visPts->Delete();
3281                                         ldm->Delete();
3282                                         smeshGUI->mySimulationActors2D->AddItem(pointLabels);
3283                                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
3284                                                 getActiveStudyFrame()->getRightFrame()->
3285                                                 getViewFrame())->getRenderer()->AddActor2D(pointLabels);
3286                                 }
3287                         }
3288                 }
3289                 else
3290                 {
3291                         QApplication::setOverrideCursor(Qt::waitCursor);
3292                         parent->menuBar()->setItemChecked(9010,
3293                                 !parent->menuBar()->isItemChecked(9010));
3294                         smeshGUI->EraseSimulationActors();
3295                         smeshGUI->ScalarVisibilityOff();
3296                 }
3297                 QApplication::restoreOverrideCursor();
3298                 break;
3299         }
3300         case 9011:
3301         {
3302                 if (!parent->menuBar()->isItemChecked(9011))
3303                 {
3304                         QApplication::setOverrideCursor(Qt::waitCursor);
3305                         parent->menuBar()->setItemChecked(9010, false);
3306
3307                         smeshGUI->EraseSimulationActors();
3308                         smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
3309
3310                         SALOME_Selection *Sel =
3311                                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3312                                 getSelection());
3313                         int nbSel = Sel->IObjectCount();
3314                         if (nbSel == 1)
3315                         {
3316                                 Standard_Boolean res;
3317                                 SMESH_Actor *MeshActor =
3318                                         smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(),
3319                                         res, true);
3320                                 if (res)
3321                                 {
3322                                         parent->menuBar()->setItemChecked(9011,
3323                                                 !parent->menuBar()->isItemChecked(9011));
3324
3325                                         // It's necessary to display SMDS IDs instead of VTK ones, so 
3326                                         // vtkIdFilter is unacceptable here. We have to do it manually :(
3327                                         vtkUnstructuredGrid *elGrid = vtkUnstructuredGrid::New();
3328                                         elGrid->CopyStructure(MeshActor->DataSource);
3329
3330                                         int numCells = MeshActor->DataSource->GetNumberOfCells();
3331
3332                                         // Loop over points and generate ids
3333                                         vtkIntArray *cellIds = vtkIntArray::New();
3334                                         cellIds->SetNumberOfValues(numCells);
3335
3336                                         for (int id = 0; id < numCells; id++)
3337                                         {
3338                                                 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
3339                                                 cellIds->SetValue(id, idSMDS);
3340                                         }
3341
3342 // mpv porting vk4.2.2
3343                                         //          vtkScalars* newScalars = vtkScalars::New();
3344                                         //          newScalars->SetData(cellIds);
3345                                         elGrid->GetCellData()->SetScalars(cellIds);
3346                                         //          elGrid->GetCellData()->SetScalars(newScalars);
3347                                         //          newScalars->Delete();
3348 //mpv
3349
3350                                         cellIds->Delete();
3351
3352                                         vtkCellCenters *cc = vtkCellCenters::New();
3353                                         cc->SetInput(elGrid);
3354
3355                                         vtkSelectVisiblePoints *visCells =
3356                                                 vtkSelectVisiblePoints::New();
3357                                         visCells->SetInput(cc->GetOutput());
3358                                         visCells->SetRenderer(((VTKViewer_ViewFrame *) smeshGUI->
3359                                                         myActiveStudy->getActiveStudyFrame()->
3360                                                         getRightFrame()->getViewFrame())->getRenderer());
3361                                         visCells->SelectInvisibleOff();
3362                                         visCells->SetTolerance(0.1);
3363                                         //        visCells->SetSelectInvisible(1);
3364
3365                                         vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
3366                                         ldm->SetInput(visCells->GetOutput());
3367                                         ldm->SetLabelFormat("%g");
3368                                         ldm->SetLabelModeToLabelScalars();
3369
3370                                         ldm->SetFontFamilyToTimes();
3371                                         ldm->SetFontSize(6 * parent->font().pointSize() / 5);
3372                                         ldm->SetBold(1);
3373                                         ldm->SetItalic(0);
3374                                         ldm->SetShadow(0);
3375
3376                                         vtkActor2D *cellLabels = vtkActor2D::New();
3377                                         cellLabels->SetMapper(ldm);
3378                                         cellLabels->GetProperty()->SetColor(1, 0, 0);
3379
3380                                         cc->Delete();
3381                                         visCells->Delete();
3382                                         ldm->Delete();
3383                                         smeshGUI->mySimulationActors2D->AddItem(cellLabels);
3384                                         ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
3385                                                 getActiveStudyFrame()->getRightFrame()->
3386                                                 getViewFrame())->getRenderer()->AddActor2D(cellLabels);
3387                                 }
3388                         }
3389                 }
3390                 else
3391                 {
3392                         QApplication::setOverrideCursor(Qt::waitCursor);
3393                         parent->menuBar()->setItemChecked(9011,
3394                                 !parent->menuBar()->isItemChecked(9011));
3395                         smeshGUI->EraseSimulationActors();
3396                         smeshGUI->ScalarVisibilityOff();
3397                 }
3398                 QApplication::restoreOverrideCursor();
3399                 break;
3400         }
3401
3402         case 10001:                             // DISPLAY MODE PREFERENCE
3403         {
3404                 parent->menuBar()->setItemChecked(10001,
3405                         !parent->menuBar()->isItemChecked(10001));
3406                 parent->menuBar()->setItemChecked(10002, false);
3407                 parent->menuBar()->setItemChecked(10003, false);
3408                 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
3409                 break;
3410         }
3411         case 10002:
3412         {
3413                 parent->menuBar()->setItemChecked(10002,
3414                         !parent->menuBar()->isItemChecked(10002));
3415                 parent->menuBar()->setItemChecked(10001, false);
3416                 parent->menuBar()->setItemChecked(10003, false);
3417                 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3418                 break;
3419         }
3420         case 10003:
3421         {
3422                 parent->menuBar()->setItemChecked(10003,
3423                         !parent->menuBar()->isItemChecked(10003));
3424                 parent->menuBar()->setItemChecked(10002, false);
3425                 parent->menuBar()->setItemChecked(10001, false);
3426                 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
3427                 break;
3428         }
3429
3430         }
3431
3432         smeshGUI->myActiveStudy->updateObjBrowser(true);
3433         return true;
3434 }
3435
3436 //=============================================================================
3437 /*! function : GetMeshesUsingAlgoOrHypothesis()
3438  *  purpose  : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
3439  *           : However is supposed here that father of father of an hypothesis is a Mesh Object.
3440  */
3441 //=============================================================================      
3442 SALOMEDS::Study::ListOfSObject *
3443         SMESHGUI::GetMeshesUsingAlgoOrHypothesis(SMESH::
3444         SMESH_Hypothesis_ptr AlgoOrHyp)
3445 {
3446         SALOMEDS::Study::ListOfSObject_var listSOmesh =
3447                 new SALOMEDS::Study::ListOfSObject;
3448         listSOmesh->length(0);
3449         unsigned int index = 0;
3450         if (!AlgoOrHyp->_is_nil())
3451         {
3452                 SALOMEDS::SObject_var SO_Hypothesis =
3453                         smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms(AlgoOrHyp);
3454                 if (!SO_Hypothesis->_is_nil())
3455                 {
3456                         SALOMEDS::Study::ListOfSObject_var listSO =
3457                                 smeshGUI->myStudy->FindDependances(SO_Hypothesis);
3458                         for (unsigned int i = 0; i < listSO->length(); i++)
3459                         {
3460                                 SALOMEDS::SObject_var SO = listSO[i];
3461                                 if (!SO->_is_nil())
3462                                 {
3463                                         SALOMEDS::SObject_var SOfatherFather =
3464                                                 SO->GetFather()->GetFather();
3465                                         if (!SOfatherFather->_is_nil())
3466                                         {
3467                                                 index++;
3468                                                 listSOmesh->length(index);
3469                                                 listSOmesh[index - 1] = SOfatherFather;
3470                                         }
3471                                 }
3472                         }
3473                 }
3474         }
3475         return listSOmesh._retn();
3476 }
3477
3478 //=============================================================================
3479 /*!
3480  *
3481  */
3482 //=============================================================================
3483 void SMESHGUI::Export_Mesh(QAD_Desktop * parent, int theCommandID)
3484 {
3485         SALOME_Selection *Sel =
3486                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3487         int nbSel = Sel->IObjectCount();
3488         if (nbSel == 1)
3489         {
3490                 Standard_Boolean res;
3491                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3492                 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(IObject, res);
3493                 if (res)
3494                 {
3495                         if (theCommandID == 122)
3496                         {                                       // EXPORT MED
3497                                 QString filename = QAD_FileDlg::getFileName(parent,
3498                                         "",
3499                                         tr("MED files (*.med)"),
3500                                         tr("Export mesh"),
3501                                         false);
3502                                 if (!filename.isEmpty())
3503                                 {
3504                                         QApplication::setOverrideCursor(Qt::waitCursor);
3505                                         aMesh->Export(filename.latin1(), "MED");
3506                                         QApplication::restoreOverrideCursor();
3507                                 }
3508                         }
3509                         else if (theCommandID == 121)
3510                         {                                       // EXPORT DAT
3511                                 QString filename = QAD_FileDlg::getFileName(parent,
3512                                         "",
3513                                         tr("DAT files (*.dat)"),
3514                                         tr("Export mesh"),
3515                                         false);
3516                                 if (!filename.isEmpty())
3517                                 {
3518                                         QApplication::setOverrideCursor(Qt::waitCursor);
3519                                         aMesh->Export(filename.latin1(), "DAT");
3520                                         QApplication::restoreOverrideCursor();
3521                                 }
3522                         }
3523                         else if (theCommandID == 123)
3524                         {                                       // EXPORT UNV
3525                                 QString filename = QAD_FileDlg::getFileName(parent,
3526                                         "",
3527                                         tr("IDEAS files (*.unv)"),
3528                                         tr("Export mesh"),
3529                                         false);
3530                                 if (!filename.isEmpty())
3531                                 {
3532                                         QApplication::setOverrideCursor(Qt::waitCursor);
3533                                         aMesh->Export(filename.latin1(), "UNV");
3534                                         QApplication::restoreOverrideCursor();
3535                                 }
3536                                 else
3537                                         aMesh->Export(filename.latin1(), "DAT");
3538
3539                                 QApplication::restoreOverrideCursor();
3540
3541                                 if (IObject->hasEntry())
3542                                 {
3543                                         MESSAGE("---");
3544                                         SALOMEDS::SObject_var SO =
3545                                                 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
3546                                         SALOMEDS::GenericAttribute_var anAttr;
3547                                         SALOMEDS::AttributeComment_var aFileName;
3548                                         SALOMEDS::StudyBuilder_var aStudyBuilder =
3549                                                 smeshGUI->myStudy->NewBuilder();
3550                                         anAttr =
3551                                                 aStudyBuilder->FindOrCreateAttribute(SO,
3552                                                 "AttributeComment");
3553                                         aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
3554                                         aFileName->SetValue(filename.latin1());
3555                                 }
3556                         }
3557                 }
3558         }
3559 }
3560
3561 //=============================================================================
3562 /*!
3563  *
3564  */
3565 //=============================================================================
3566 void SMESHGUI::Import_Document(QAD_Desktop * parent, int theCommandID)
3567 {
3568         QString filter;
3569         string myExtension;
3570
3571         if (theCommandID == 113)
3572         {
3573                 filter = tr("MED files (*.med)");
3574                 myExtension = string("MED");
3575         }
3576         else if (theCommandID == 112)
3577         {
3578                 filter = tr("IDEAS files (*.unv)");
3579                 myExtension = string("UNV");
3580         }
3581         else if (theCommandID == 111)
3582         {
3583                 filter = tr("DAT files (*.dat)");
3584                 myExtension = string("DAT");
3585         }
3586
3587         QString filename = QAD_FileDlg::getFileName(parent, "", filter,
3588                 tr("Import document"), true);
3589
3590         if (!filename.isEmpty())
3591         {
3592                 QApplication::setOverrideCursor(Qt::waitCursor);
3593                 try
3594                 {
3595                         if (!myComponentMesh->_is_nil())
3596                         {
3597                                 SMESH::SMESH_Mesh_var aMesh =
3598                                         myComponentMesh->Import(myStudyId, filename.latin1(),
3599                                         myExtension.c_str());
3600         
3601                                 if (!aMesh->_is_nil())
3602                                 {
3603                                         SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh(aMesh);
3604                                         myStudyAPI.SetName(SM, filename);
3605                                 }
3606                         }
3607                 }
3608                 catch(const SALOME::SALOME_Exception & S_ex)
3609                 {
3610                         QtCatchCorbaException(S_ex);
3611                 }
3612                 myActiveStudy->updateObjBrowser(true);
3613                 QApplication::restoreOverrideCursor();
3614         }
3615 }
3616
3617 //=============================================================================
3618 /*!
3619  *
3620  */
3621 //=============================================================================
3622 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3623         QAD_StudyFrame * studyFrame)
3624 {
3625         SMESHGUI::GetOrCreateSMESHGUI(parent);
3626         return false;
3627 }
3628
3629 //=============================================================================
3630 /*!
3631  *
3632  */
3633 //=============================================================================
3634 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3635         QAD_StudyFrame * studyFrame)
3636 {
3637         SMESHGUI::GetOrCreateSMESHGUI(parent);
3638
3639         return true;
3640 }
3641
3642 //=============================================================================
3643 /*!
3644  *
3645  */
3646 //=============================================================================
3647 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3648         QAD_StudyFrame * studyFrame)
3649 {
3650         SMESHGUI::GetOrCreateSMESHGUI(parent);
3651
3652         return true;
3653 }
3654
3655 //=============================================================================
3656 /*!
3657  *
3658  */
3659 //=============================================================================
3660 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
3661 {
3662         SMESHGUI::GetOrCreateSMESHGUI(parent);
3663
3664         /* Display mode */
3665         QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3666         if (DisplayMode.compare("") == 0)
3667         {
3668                 DisplayMode = "Shading";
3669                 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3670         }
3671
3672         if (DisplayMode.compare("Wireframe") == 0)
3673         {
3674                 parent->menuBar()->setItemChecked(10003, false);
3675                 parent->menuBar()->setItemChecked(10002, false);
3676                 parent->menuBar()->setItemChecked(10001, true);
3677         }
3678         else if (DisplayMode.compare("Shading") == 0)
3679         {
3680                 parent->menuBar()->setItemChecked(10003, false);
3681                 parent->menuBar()->setItemChecked(10002, true);
3682                 parent->menuBar()->setItemChecked(10001, false);
3683         }
3684         else if (DisplayMode.compare("Shrink") == 0)
3685         {
3686                 parent->menuBar()->setItemChecked(10003, true);
3687                 parent->menuBar()->setItemChecked(10002, false);
3688                 parent->menuBar()->setItemChecked(10001, false);
3689         }
3690
3691         /* Automatic Update */
3692         QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3693         if (AutoUpdate.compare("true") == 0)
3694         {
3695                 parent->menuBar()->setItemChecked(1001, true);
3696                 smeshGUI->myAutomaticUpdate = true;
3697         }
3698         else
3699         {
3700                 parent->menuBar()->setItemChecked(1001, false);
3701                 smeshGUI->myAutomaticUpdate = false;
3702         }
3703
3704         return true;
3705 }
3706
3707 //=============================================================================
3708 /*!
3709  *
3710  */
3711 //=============================================================================
3712 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent,
3713         QString & theObject)
3714 {
3715         /* Create or retrieve an object SMESHGUI */
3716         SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3717
3718         // NRI : Temporary added
3719         //  if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3720         //    theObject = "NothingSelected";
3721         //    theContext = "NothingSelected";
3722         //  }
3723         // NRI
3724
3725         SALOME_Selection *Sel =
3726                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3727         int nbSel = Sel->IObjectCount();
3728         if (nbSel == 0)
3729         {
3730                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3731                         VIEW_VTK)
3732                 {
3733                         vtkScalarBarActor *aScalarBar = smeshGUI->GetScalarBar();
3734                         if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1))
3735                         {
3736                                 theObject = "ScalarBar";
3737                                 theContext = "";
3738                         }
3739                         else
3740                         {
3741                                 theObject = "NothingSelected";
3742                                 theContext = "NothingSelected";
3743                         }
3744                 }
3745                 else
3746                 {
3747                         theObject = "NothingSelected";
3748                         theContext = "NothingSelected";
3749                 }
3750         }
3751         else if (nbSel == 1)
3752         {
3753                 theObject = smeshGUI->CheckTypeObject(Sel->firstIObject());
3754                 theContext = "";
3755         }
3756         else
3757         {
3758                 theObject = smeshGUI->CheckHomogeneousSelection();
3759                 theContext = "";
3760         }
3761 }
3762
3763 //=============================================================================
3764 /*!
3765  *
3766  */
3767 //=============================================================================
3768 bool SMESHGUI::CustomPopup(QAD_Desktop * parent,
3769         QPopupMenu * popup,
3770         const QString & theContext,
3771         const QString & theParent, const QString & theObject)
3772 {
3773         // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3774         //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3775         //  return false;
3776         /* Create or retrieve an object SMESHGUI */
3777         SMESHGUI::GetOrCreateSMESHGUI(parent);
3778
3779         // NRI : Temporary added
3780         //  if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3781         //    return false;
3782         //  }
3783         // NRI
3784
3785         SALOME_Selection *Sel =
3786                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3787         QAD_StudyFrame *studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3788         int nbSel = Sel->IObjectCount();
3789
3790         if (nbSel == 0)
3791         {
3792                 if (studyFrame->getTypeView() != VIEW_VTK)
3793                         popup->clear();
3794                 return false;
3795         }
3796         else if (nbSel == 1)
3797         {
3798                 QString parentComp =
3799                         ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
3800                 // First check type of active viewer (VTK required)
3801                 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
3802                         parent->getActiveComponent())
3803                 {
3804                         //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3805                         while (1)
3806                         {
3807                                 int id = popup->idAt(0);
3808                                 if (id <= QAD_TopLabel_Popup_ID)
3809                                         popup->removeItemAt(0);
3810                                 else
3811                                         break;
3812                         }
3813                         if (theObject.compare("Component") == 0)
3814                         {
3815                                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3816                         }
3817                         return false;
3818                 }
3819
3820                 // Remove common popup items for Submesh, Hypothesis and Algorithm
3821                 if (theObject.compare("SubMesh") == 0 ||
3822                         theObject.compare("Hypothesis") == 0 ||
3823                         theObject.compare("Algorithm") == 0)
3824                 {
3825                         popup->removeItem(QAD_Display_Popup_ID);
3826                         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3827                         popup->removeItem(QAD_Erase_Popup_ID);
3828                         int id = popup->idAt(popup->count() - 1);       // last item
3829                         if (id < 0 && id != -1)
3830                                 popup->removeItem(id);  // separator
3831                 }
3832
3833                 if (theObject.compare("Component") == 0)
3834                 {
3835                         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3836                         return true;
3837                 }
3838
3839                 int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
3840                 QFont f = QApplication::font();
3841                 f.setBold(TRUE);
3842
3843                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3844
3845                 if (theParent.compare("Viewer") == 0)
3846                 {
3847                         if (popup->idAt(0) == id)
3848                         {
3849                                 popup->removeItem(id);
3850                                 popup->insertItem(new CustomItem(QString(IObject->getName()),
3851                                                 f), id, 0);
3852                         }
3853
3854                         Standard_Boolean res;
3855                         SMESH_Actor *ac =
3856                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3857                         if (res && studyFrame->getTypeView() == VIEW_VTK)
3858                         {
3859                                 VTKViewer_RenderWindowInteractor *myRenderInter =
3860                                         ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
3861                                         getViewFrame())->getRWInteractor();
3862                                 if (myRenderInter->isVisible(IObject))
3863                                 {
3864                                         popup->removeItem(QAD_Display_Popup_ID);
3865                                 }
3866                                 else
3867                                 {
3868                                         popup->removeItem(QAD_Erase_Popup_ID);
3869                                 }
3870                         }
3871                         else
3872                         {
3873                                 popup->removeItem(QAD_Erase_Popup_ID);
3874                                 if (!res)
3875                                 {                               // mesh not computed -> can't display it
3876                                         popup->removeItem(QAD_Display_Popup_ID);
3877                                         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3878                                         popup->removeItemAt(popup->count() - 1);        //separator
3879                                 }
3880                         }
3881                 }
3882                 else if (theParent.compare("ObjectBrowser") == 0)
3883                 {
3884                         if (theObject.compare("Mesh") == 0 ||
3885                                 theObject.compare("SubMesh") == 0 ||
3886                                 theObject.compare("Hypothesis") == 0 ||
3887                                 theObject.compare("Algorithm") == 0)
3888                         {
3889                                 popup->removeItemAt(0);
3890                         }
3891                         else
3892                         {
3893                                 if (popup->idAt(0) == id)
3894                                 {
3895                                         popup->removeItem(id);
3896                                         popup->removeItemAt(0); //separator
3897                                 }
3898                         }
3899
3900                         Standard_Boolean res;
3901                         SMESH_Actor *ac =
3902                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3903                         if (res && studyFrame->getTypeView() == VIEW_VTK)
3904                         {
3905                                 VTKViewer_RenderWindowInteractor *myRenderInter =
3906                                         ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
3907                                         getViewFrame())->getRWInteractor();
3908                                 if (myRenderInter->isVisible(IObject))
3909                                 {
3910                                         popup->removeItem(QAD_Display_Popup_ID);
3911                                 }
3912                                 else
3913                                 {
3914                                         popup->removeItem(QAD_Erase_Popup_ID);
3915                                 }
3916                         }
3917                         else
3918                         {
3919                                 if (theObject.compare("Mesh") == 0 ||
3920                                         theObject.compare("SubMesh") == 0 ||
3921                                         theObject.compare("Hypothesis") == 0 ||
3922                                         theObject.compare("Algorithm") == 0)
3923                                 {
3924                                 }
3925                                 else
3926                                 {
3927                                         popup->removeItem(QAD_Erase_Popup_ID);
3928                                         if (!res)
3929                                         {                       // mesh not computed -> can't display it
3930                                                 popup->removeItem(QAD_Display_Popup_ID);
3931                                                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3932                                                 popup->removeItemAt(popup->count() - 1);        //separator
3933                                         }
3934                                 }
3935                         }
3936                 }
3937         }
3938         else
3939         {
3940                 QString parentComp =
3941                         ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
3942                 QAD_StudyFrame *studyFrame =
3943                         smeshGUI->myActiveStudy->getActiveStudyFrame();
3944                 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
3945                         parent->getActiveComponent())
3946                 {
3947                         //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3948                         while (1)
3949                         {
3950                                 int id = popup->idAt(0);
3951                                 if (id <= QAD_TopLabel_Popup_ID && id != -1)
3952                                         popup->removeItemAt(0);
3953                                 else
3954                                         break;
3955                         }
3956                         if (parentComp.isNull())
3957                         {                                       // objects from several components are selected
3958                                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3959                                 popup->removeItem(QAD_Display_Popup_ID);
3960                                 popup->removeItem(QAD_Erase_Popup_ID);
3961                                 int id = popup->idAt(popup->count() - 1);       // last item
3962                                 if (id < 0 && id != -1)
3963                                         popup->removeItem(id);  // separator
3964                         }
3965                         return false;
3966                 }
3967
3968                 QString type = smeshGUI->CheckHomogeneousSelection();
3969                 if (type.compare("Heterogeneous Selection") != 0)
3970                 {
3971                         int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
3972                         QFont f = QApplication::font();
3973                         f.setBold(TRUE);
3974                         popup->removeItem(id);
3975                         popup->insertItem(new CustomItem(QString("%1 ").arg(nbSel) + type +
3976                                         " (s) ", f), id, 0);
3977                 }
3978         }
3979         return false;
3980 }
3981
3982 /**
3983  * Ensures that the actor for the given <theIO> exists in the active VTK view
3984  * @TODO Handle multiple selection.
3985  */
3986 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
3987 {
3988         MESSAGE("SMESHGUI::BuildPresentation("<<theIO->getEntry()<<")");
3989         /* Create or retrieve an object SMESHGUI */
3990         SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3991
3992         QAD_StudyFrame *activeFrame =
3993                 smeshGUI->myActiveStudy->getActiveStudyFrame();
3994         if (activeFrame->getTypeView() == VIEW_VTK)
3995         {
3996                 // VTK
3997                 // Some ideas to handle multiple selection...
3998                 /*SALOMEDS::SObject_var fatherSF =
3999                         smeshGUI->myStudy->FindObjectID(activeFrame->entry());
4000
4001                 SALOME_Selection *Sel =
4002                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
4003                         getSelection());
4004                 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4005
4006             for(;It.More();It.Next()) {
4007       Handle(SALOME_InteractiveObject) IObject = It.Value();*/
4008                 Handle(SALOME_InteractiveObject) IObject = theIO;
4009                 if (IObject->hasEntry())
4010                 {
4011                         // Look for the actor in all views
4012                         Standard_Boolean res;
4013                         SMESH_Actor *ac =
4014                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
4015                         
4016                         if (!res)
4017                         {
4018                                 SALOMEDS::SObject_var aMorSM=smeshGUI->myStudy->FindObjectID( IObject->getEntry());
4019                                 SALOMEDS::GenericAttribute_var anAttr;
4020                                 SALOMEDS::AttributeIOR_var     anIOR;
4021                                 if(aMorSM->FindAttribute(anAttr, "AttributeIOR"))
4022                                 {
4023                                         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4024                                         SMESH::SMESH_Mesh_var aM =
4025                                                 SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()));
4026                                         if(!aM->_is_nil())
4027                                         {
4028                                                 smeshGUI->InitActor(aM);
4029                                                 ac = smeshGUI->ReadScript(aM);
4030                                                 smeshGUI->DisplayActor( ac, true );
4031                                                 smeshGUI->DisplayEdges( ac );
4032                                                 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
4033                                         }
4034                                         else
4035                                         {
4036                                                 MESSAGE("Do not know how to display something which is not a SMESH_Mesh");
4037                                         }
4038                                 }
4039                                 else
4040                                 {
4041                                         MESSAGE("The object "<<theIO->getEntry()<<
4042                                                 " do not have \"AttributeIOR\" attribute");
4043                                 }
4044                         }
4045                         else
4046                         {
4047                                 // The actor exists in some view
4048                                 // Check whether the actor belongs to the active view
4049                                 VTKViewer_RenderWindowInteractor *rwInter =
4050                                         ((VTKViewer_ViewFrame *) activeFrame->getRightFrame()->
4051                                         getViewFrame())->getRWInteractor();
4052
4053                                 // The actor belongs to inactive view -> create a copy and display it in the active view
4054                                 if (!rwInter->isInViewer(IObject))
4055                                 {
4056                                         if(ac->GetMapper()==NULL)
4057                                         {
4058                                                 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(theIO, res);
4059                                                 ac=smeshGUI->ReadScript(aMesh);
4060                                         }
4061                                         SMESH_Actor *acCopy = SMESH_Actor::New();
4062                                         acCopy->ShallowCopy(ac);
4063                                         ac = acCopy;
4064                                 }
4065                                 smeshGUI->DisplayActor(ac, false);
4066                                 smeshGUI->DisplayEdges(ac);
4067                                 smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
4068                         }
4069                 }
4070         }
4071         else
4072         {
4073                 MESSAGE("BuildPresentation() must not be called while non-VTK view is active");
4074         }
4075 }
4076
4077 //=============================================================================
4078 /*!
4079  *
4080  */
4081 //=============================================================================
4082 void SMESHGUI::setOrb()
4083 {
4084         try
4085         {
4086                 ORB_INIT & init = *SINGLETON_ < ORB_INIT >::Instance();
4087                 ASSERT(SINGLETON_ < ORB_INIT >::IsAlreadyExisting());
4088                 _orb = init(0, 0);
4089         } catch(...)
4090         {
4091                 INFOS("internal error : orb not found");
4092                 _orb = 0;
4093         }
4094         ASSERT(!CORBA::is_nil(_orb));
4095 }
4096
4097 /**
4098  * Get the history of all commands made in the SMESH server. This list of command
4099  * is used to display the mesh in the VTK view
4100  * @TODO Handle the REMOVE_ALL command.
4101  */
4102 SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
4103 {
4104         MESSAGE("SMESHGUI::ReadScript");
4105         SMESH_Actor *MeshActor;
4106         if (!aMesh->_is_nil())
4107         {
4108                 Standard_Boolean result;
4109                 MeshActor = FindActor(aMesh, result, false);
4110                 if (result)
4111                 {
4112                         SMESH::log_array_var aSeq = aMesh->GetLog(true);
4113                         MESSAGE("SMESHGUI::ReadScript: The log contains "<<aSeq->length()
4114                                 <<" commands.");
4115
4116                         for (unsigned int ind = 0; ind < aSeq->length(); ind++)
4117                         {
4118                                 switch (aSeq[ind].commandType)
4119                                 {
4120                                 case SMESH::ADD_NODE:
4121                                 {
4122                                         AddNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4123                                                 aSeq[ind].indexes);
4124                                         break;
4125                                 }
4126                                 case SMESH::ADD_EDGE:
4127                                 {
4128                                         //          AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
4129                                         break;
4130                                 }
4131                                 case SMESH::ADD_TRIANGLE:
4132                                 {
4133                                         AddTriangles(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4134                                                 aSeq[ind].indexes);
4135                                         break;
4136                                 }
4137                                 case SMESH::ADD_QUADRANGLE:
4138                                 {
4139                                         AddQuadrangles(MeshActor, aSeq[ind].number,
4140                                                 aSeq[ind].coords, aSeq[ind].indexes);
4141                                         break;
4142                                 }
4143                                 case SMESH::ADD_TETRAHEDRON:
4144                                 {
4145                                         AddTetras(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4146                                                 aSeq[ind].indexes);
4147                                         break;
4148                                 }
4149                                 case SMESH::ADD_PYRAMID:
4150                                 {
4151                                         break;
4152                                 }
4153                                 case SMESH::ADD_PRISM:
4154                                 {
4155                                         break;
4156                                 }
4157                                 case SMESH::ADD_HEXAHEDRON:
4158                                 {
4159                                         AddHexaedres(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4160                                                 aSeq[ind].indexes);
4161                                         break;
4162                                 }
4163                                 case SMESH::REMOVE_NODE:
4164                                 {
4165                                         RemoveNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4166                                                 aSeq[ind].indexes);
4167                                         break;
4168                                 }
4169                                 case SMESH::REMOVE_ELEMENT:
4170                                 {
4171                                         RemoveElements(MeshActor, aSeq[ind].number,
4172                                                 aSeq[ind].coords, aSeq[ind].indexes);
4173                                         break;
4174                                 }
4175                                 case SMESH::REMOVE_ALL:
4176                                         MESSAGE("REMOVE_ALL command not yet implemented");
4177                                         break;
4178                                 default: MESSAGE("Warning: Unknown script command.");
4179                                 }
4180                         }
4181                         return MeshActor;
4182                 }
4183         }
4184         return NULL;
4185 }
4186
4187 //=============================================================================
4188 /*!
4189  *
4190  */
4191 //=============================================================================
4192 void SMESHGUI::Dump(SMESH_Actor * Mactor)
4193 {
4194         vtkUnstructuredGrid *ugrid =
4195                 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
4196         vtkPoints *Pts = ugrid->GetPoints();
4197         int nbPts = Pts->GetNumberOfPoints();
4198         int nbCells = ugrid->GetNumberOfCells();
4199
4200         FILE *In;
4201         int i, j;
4202         In = fopen("/tmp/dumpMesh", "w+");
4203         fprintf(In, "%d %d\n", nbPts, nbCells);
4204         for (int i = 0; i < nbPts; i++)
4205         {
4206                 float *p = ugrid->GetPoint(i);
4207                 fprintf(In, "%d %e %e %e\n", i, p[0], p[1], p[2]);
4208         }
4209
4210         for (int i = 0; i < nbCells; i++)
4211         {
4212                 fprintf(In, "%d %d", i, ugrid->GetCell(i)->GetCellType());
4213                 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
4214                 for (j = 0; j < Id->GetNumberOfIds(); j++)
4215                 {
4216                         fprintf(In, " %d", Id->GetId(j));
4217                 }
4218                 fprintf(In, "\n");
4219         }
4220         fclose(In);
4221 }
4222
4223 //=============================================================================
4224 /*!
4225  *
4226  */
4227 //=============================================================================
4228 void SMESHGUI::AddNodes(SMESH_Actor * Mactor, int number,
4229         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4230 {
4231         MESSAGE("SMESHGUI::AddNodes(number="<<number<<", indexes.length()="<<indexes.length()<<")");
4232         QApplication::setOverrideCursor(Qt::waitCursor);
4233         if (Mactor->GetMapper() == NULL)
4234         {
4235                 vtkPoints *Pts = vtkPoints::New();
4236                 SMESH_Grid *ugrid = SMESH_Grid::New();
4237                 ugrid->Allocate();
4238
4239                 int i = 1;
4240                 int j = 1;
4241                 while (i <= number)
4242                 {
4243                         int idVTK =
4244                                 Pts->InsertNextPoint(coords[j - 1], coords[j], coords[j + 1]);
4245                         //Mactor->AddNode( indexes[i-1], idVTK );
4246                         ugrid->AddNode(indexes[i - 1], idVTK);
4247                         i++;
4248                         j = j + 3;
4249                 }
4250                 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4251                 ugrid->SetPoints(Pts);
4252                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4253                 PtsMapper->SetInput(ugrid);
4254                 Mactor->DataSource = PtsMapper->GetInput();
4255                 Mactor->SetMapper(PtsMapper);
4256         }
4257         else
4258         {
4259                 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4260                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4261                 int i = 1;
4262                 int j = 1;
4263                 while (i <= number)
4264                 {
4265                         int idVTK =
4266                                 ugrid->GetPoints()->InsertNextPoint(coords[j - 1], coords[j],
4267                                 coords[j + 1]);
4268                         ugrid->AddNode(indexes[i - 1], idVTK);
4269                         i++;
4270                         j = j + 3;
4271                 }
4272                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4273                 PtsMapper->SetInput(ugrid);
4274                 Mactor->DataSource = PtsMapper->GetInput();
4275                 Mactor->SetMapper(PtsMapper);
4276         }
4277         QApplication::restoreOverrideCursor();
4278 }
4279
4280 //=============================================================================
4281 /*!
4282  *
4283  */
4284 //=============================================================================
4285 void SMESHGUI::AddNode(SMESH_Actor * Mactor, int idnode, float x, float y,
4286         float z)
4287 {
4288         QApplication::setOverrideCursor(Qt::waitCursor);
4289         MESSAGE("SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z);
4290         
4291         if (Mactor->GetMapper() == NULL)
4292         {
4293                 vtkPoints *Pts = vtkPoints::New();
4294                 int idVTK = Pts->InsertNextPoint(x, y, z);
4295                 //Mactor->AddNode( idnode, idVTK );
4296                 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4297                 SMESH_Grid *ugrid = SMESH_Grid::New();
4298                 ugrid->Allocate();
4299                 ugrid->AddNode(idnode, idVTK);
4300                 ugrid->SetPoints(Pts);
4301                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4302                 PtsMapper->SetInput(ugrid);
4303                 Mactor->DataSource = PtsMapper->GetInput();
4304                 Mactor->SetMapper(PtsMapper);
4305         }
4306         else
4307         {
4308                 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4309                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4310                 int idVTK = ugrid->GetPoints()->InsertNextPoint(x, y, z);
4311                 //Mactor->AddNode( idnode, idVTK );
4312                 ugrid->AddNode(idnode, idVTK);
4313                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4314                 PtsMapper->SetInput(ugrid);
4315                 Mactor->DataSource = PtsMapper->GetInput();
4316                 Mactor->SetMapper(PtsMapper);
4317         }
4318         QApplication::restoreOverrideCursor();
4319 }
4320
4321 //=============================================================================
4322 /*!
4323  *
4324  */
4325 //=============================================================================
4326 void SMESHGUI::RemoveNode(SMESH_Actor * Mactor, int idnode)
4327 {
4328         MESSAGE(" OLD RemoveNode method ")
4329 //   int id = Mactor->GetIdVTKNode( idnode );
4330 //    MESSAGE ( " RemoveNode id VTK " << id )
4331 //    if ( Mactor->GetMapper() != NULL ) {
4332 //      vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4333 //      vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4334 //      vtkPoints *Pts = ugrid->GetPoints();
4335 //      vtkPoints *newPts = vtkPoints::New();
4336 //      int nbPts = Pts->GetNumberOfPoints();
4337 //      bool findPt = false;
4338 //      for ( int i = 0; i < nbPts; i++ ) {
4339 //        if ( id != i ) {
4340 //      if ( !findPt)
4341 //        newPts->InsertPoint(i, Pts->GetPoint(i) );
4342 //      else
4343 //        newPts->InsertPoint(i-1, Pts->GetPoint(i) );
4344 //        } else {
4345 //      findPt = true;
4346 //      Mactor->RemoveNode( idnode );
4347 //        }
4348 //      }
4349 //      newUgrid->SetPoints(newPts);
4350 //      int nbCells = ugrid->GetNumberOfCells();
4351 //      for ( int i = 0; i < nbCells; i++ ) {
4352 //        vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4353 //        vtkIdList *newIds = vtkIdList::New();
4354 //        int nbIds = Ids->GetNumberOfIds();
4355 //        newIds->SetNumberOfIds(nbIds);
4356 //        for ( int j = 0; j < nbIds; j++ ) {
4357 //      int theid = Ids->GetId(j);
4358 //      if ( theid > id ) {
4359 //        newIds->SetId( j, theid-1 );
4360 //      } else
4361 //        newIds->SetId( j, theid );
4362 //        }
4363 //        int idSMDSel = Mactor->GetIdSMESHDSElement( i );
4364 //        Mactor->RemoveElement( idSMDSel, false );
4365 //        int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
4366 //        Mactor->AddElement( idSMDSel, idVTKel );
4367 //      }
4368 //      vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4369 //      Mapper->SetInput( newUgrid );
4370 //      Mactor->DataSource = Mapper->GetInput();
4371 //      Mactor->SetMapper(Mapper);
4372 //      UpdateView();
4373 //    }
4374 }
4375
4376 //=============================================================================
4377 /*!
4378  *
4379  */
4380 //=============================================================================
4381 void SMESHGUI::RemoveNodes(SMESH_Actor * Mactor, int number,
4382         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4383 {
4384         QApplication::setOverrideCursor(Qt::waitCursor);
4385         int i = 1;
4386         while (i <= number)
4387         {
4388                 Mactor->RemoveNode(indexes[i - 1]);
4389                 i++;
4390         }
4391
4392         TColStd_DataMapOfIntegerInteger newMapVTKNodes;
4393         TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
4394         TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
4395
4396         if (Mactor->GetMapper() != NULL)
4397         {
4398                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4399                 SMESH_Grid *newUgrid = SMESH_Grid::New();
4400                 newUgrid->CopyMaps(ugrid);
4401
4402                 vtkPoints *Pts = ugrid->GetPoints();
4403                 vtkPoints *newPts = vtkPoints::New();
4404                 int nbPts = Pts->GetNumberOfPoints();
4405                 int j = 0;
4406                 for (int i = 0; i < nbPts; i++)
4407                 {
4408                         int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
4409                         if (idSMESHDSNode != -1)
4410                         {
4411                                 newPts->InsertPoint(j, Pts->GetPoint(i));
4412
4413                                 newMapVTKNodes.Bind(j, idSMESHDSNode);
4414                                 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
4415
4416                                 MapOldNodesToNewNodes.Bind(i, j);
4417                                 j++;
4418                         }
4419                 }
4420
4421                 newUgrid->SetIdsVTKNode(newMapVTKNodes);
4422                 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
4423                 newUgrid->SetPoints(newPts);
4424
4425                 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4426                 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4427
4428                 int nbCells = ugrid->GetNumberOfCells();
4429                 for (int i = 0; i < nbCells; i++)
4430                 {
4431                         vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4432                         vtkIdList *newIds = vtkIdList::New();
4433                         int nbIds = Ids->GetNumberOfIds();
4434                         newIds->SetNumberOfIds(nbIds);
4435                         bool isGood = true;
4436                         for (int j = 0; j < nbIds; j++)
4437                         {
4438                                 int theid = Ids->GetId(j);
4439                                 if (MapOldNodesToNewNodes.IsBound(theid))
4440                                 {
4441                                         newIds->SetId(j, MapOldNodesToNewNodes.Find(theid));
4442                                 }
4443                                 else
4444                                 {
4445                                         isGood = false;
4446                                         break;
4447                                 }
4448                         }
4449
4450                         // Filtering out cells based on non-existing nodes
4451                         if (isGood)
4452                         {
4453                                 int idSMDSel = Mactor->GetIdSMESHDSElement(i);
4454                                 int idVTKel =
4455                                         newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4456                                         newIds);
4457
4458                                 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
4459                                 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
4460                         }
4461                 }
4462
4463                 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4464                 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4465
4466                 // Copy new data to the old DatSource: keep the single DataSource for all actors
4467                 ugrid->DeepCopy(newUgrid);
4468
4469                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4470                 Mapper->SetInput(ugrid);
4471                 Mactor->SetMapper(Mapper);
4472
4473                 // Commented to avoid multiple viewer updates when called by ReadScript()
4474                 //UpdateView();
4475
4476         }
4477         QApplication::restoreOverrideCursor();
4478 }
4479
4480 //=============================================================================
4481 /*!
4482  *
4483  */
4484 //=============================================================================
4485 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh,
4486         const TColStd_MapOfInteger & MapIndex)
4487 {
4488         QApplication::setOverrideCursor(Qt::waitCursor);
4489         Standard_Boolean result;
4490         SMESH_Actor *ac = FindActor(aMesh, result, true);
4491         if (result)
4492         {
4493                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4494                 anArrayOfIdeces->length(MapIndex.Extent());
4495                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4496                 int i = 0;
4497                 for (; ite.More(); ite.Next())
4498                 {
4499                         //      MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
4500                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
4501                         i++;
4502                 }
4503                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4504                 aMeshEditor->RemoveNodes(anArrayOfIdeces);
4505
4506         }
4507         if (myAutomaticUpdate)
4508         {
4509                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4510                 if (Mesh != NULL)
4511                 {
4512                         smeshGUI->DisplayActor(Mesh);
4513                         smeshGUI->DisplayEdges(Mesh);
4514                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4515                         AddActorInSelection(Mesh);
4516                 }
4517         }
4518         QApplication::restoreOverrideCursor();
4519 }
4520
4521 //=============================================================================
4522 /*!
4523  *
4524  */
4525 //=============================================================================
4526 void SMESHGUI::RemoveElement(SMESH_Actor * Mactor, int idelement)
4527 {
4528         MESSAGE(" OLD RemoveElement method ")
4529 //    int id = Mactor->GetIdVTKElement( idelement );
4530 //    MESSAGE ( " RemoveElement id VTK : " << id )
4531 //    if ( Mactor->GetMapper() != NULL ) {
4532 //      vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4533 //      vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4534 //      int nbCells = ugrid->GetNumberOfCells();
4535 //      for ( int i = 0; i < nbCells; i++ ) {
4536 //        if ( id != i ) {
4537 //      newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), 
4538 //                    ugrid->GetCell(i)->GetPointIds() );
4539 //        } else
4540 //      Mactor->RemoveElement( idelement );
4541 //      }
4542 //      newUgrid->SetPoints(ugrid->GetPoints());
4543 //      vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4544 //      Mapper->SetInput( newUgrid );
4545 //      Mactor->DataSource = Mapper->GetInput();
4546 //      Mactor->SetMapper(Mapper);
4547 //      UpdateView();
4548 //    }
4549 }
4550
4551 //=============================================================================
4552 /*!
4553  *
4554  */
4555 //=============================================================================
4556 void SMESHGUI::RemoveElements(SMESH_Actor * Mactor, int number,
4557         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4558 {
4559         QApplication::setOverrideCursor(Qt::waitCursor);
4560         int i = 1;
4561         while (i <= number)
4562         {
4563                 Mactor->RemoveElement(indexes[i - 1]);
4564                 i++;
4565         }
4566         TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4567         TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4568
4569         if (Mactor->GetMapper() != NULL)
4570         {
4571                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4572                 SMESH_Grid *newUgrid = SMESH_Grid::New();
4573                 newUgrid->CopyMaps(ugrid);
4574
4575                 int nbCells = ugrid->GetNumberOfCells();
4576                 for (int i = 0; i < nbCells; i++)
4577                 {
4578                         int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
4579                         if (idSMESHDSElement != -1)
4580                         {
4581                                 int newId =
4582                                         newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4583                                         ugrid->GetCell(i)->GetPointIds());
4584                                 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
4585                                 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
4586                         }
4587                 }
4588
4589                 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4590                 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4591
4592                 newUgrid->SetPoints(ugrid->GetPoints());
4593
4594                 // Copy new data to the old DatSource: keep the single DataSource for all actors
4595                 ugrid->DeepCopy(newUgrid);
4596
4597                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4598                 Mapper->SetInput(ugrid);
4599                 Mactor->SetMapper(Mapper);
4600
4601                 // Commented to avoid multiple viewer updates when called by ReadScript()
4602                 //UpdateView();
4603         }
4604         QApplication::restoreOverrideCursor();
4605 }
4606
4607 //=============================================================================
4608 /*!
4609  *
4610  */
4611 //=============================================================================
4612 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh,
4613         const TColStd_MapOfInteger & MapIndex)
4614 {
4615         QApplication::setOverrideCursor(Qt::waitCursor);
4616         Standard_Boolean result;
4617         SMESH_Actor *ac = FindActor(aMesh, result, true);
4618         if (result)
4619         {
4620                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4621                 anArrayOfIdeces->length(MapIndex.Extent());
4622                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4623                 int i = 0;
4624                 for (; ite.More(); ite.Next())
4625                 {
4626                         //      MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
4627                         anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
4628                         i++;
4629                 }
4630
4631                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4632                 aMeshEditor->RemoveElements(anArrayOfIdeces);
4633         }
4634
4635         if (myAutomaticUpdate)
4636         {
4637                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4638                 if (Mesh != NULL)
4639                 {
4640                         smeshGUI->DisplayActor(Mesh);
4641                         smeshGUI->DisplayEdges(Mesh);
4642                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4643                         AddActorInSelection(Mesh);
4644 #ifdef TRACE
4645                         Dump(Mesh);
4646 #endif
4647                 }
4648         }
4649         QApplication::restoreOverrideCursor();
4650 }
4651
4652 //=============================================================================
4653 /*!
4654  *
4655  */
4656 //=============================================================================
4657 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh,
4658         const TColStd_MapOfInteger & MapIndex)
4659 {
4660         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4661                 return;
4662
4663         vtkRenderer *theRenderer =
4664                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4665                 getRightFrame()->getViewFrame())->getRenderer();
4666         Standard_Boolean result;
4667         SMESH_Actor *ac = FindActor(aMesh, result, true);
4668         if (result)
4669         {
4670                 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4671                 SMESH_Grid *UGrid = SMESH_Grid::New();
4672                 SMESH_Grid *oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
4673                 UGrid->CopyMaps(oldGrid);
4674
4675                 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4676                 gf->SetInput(ac->DataSource);
4677
4678                 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4679                 Mapper->SetInput(gf->GetOutput());
4680                 Mapper->Update();
4681
4682                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4683                 for (; ite.More(); ite.Next())
4684                 {
4685                         Mapper->GetInput()->ReverseCell(ite.Key());
4686                 }
4687
4688                 UGrid->SetPoints(Mapper->GetInput()->GetPoints());
4689                 int nbCells = Mapper->GetInput()->GetNumberOfCells();
4690                 for (int i = 0; i < nbCells; i++)
4691                 {
4692                         UGrid->InsertNextCell(Mapper->GetInput()->GetCellType(i),
4693                                 Mapper->GetInput()->GetCell(i)->GetPointIds());
4694                 }
4695
4696                 // Copy new data to the old DatSource: keep the single DataSource for all actors
4697                 oldGrid->DeepCopy(UGrid);
4698
4699                 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4700                 //NewMapper->SetInput( UGrid );
4701                 NewMapper->SetInput(oldGrid);
4702                 NewMapper->Update();
4703
4704                 //ac->DataSource = NewMapper->GetInput();
4705                 ac->SetMapper(NewMapper);
4706         }
4707         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4708         renWin->Render();
4709         QApplication::restoreOverrideCursor();
4710 }
4711
4712 //=============================================================================
4713 /*!
4714  *
4715  */
4716 //=============================================================================
4717 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh,
4718         const TColStd_MapOfInteger & MapIndex)
4719 {
4720         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4721                 return;
4722
4723         QApplication::setOverrideCursor(Qt::waitCursor);
4724         vtkRenderer *theRenderer =
4725                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4726                 getRightFrame()->getViewFrame())->getRenderer();
4727         Standard_Boolean result;
4728
4729         SMESH_Actor *ac = FindActor(aMesh, result, true);
4730         if (result)
4731         {
4732                 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4733                 SMESH_Grid *UGrid = SMESH_Grid::New();
4734                 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4735                 gf->SetInput(ac->DataSource);
4736
4737                 vtkExtractEdges *edges = vtkExtractEdges::New();
4738                 edges->SetInput(ac->DataSource);
4739
4740                 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4741                 Mapper->SetInput(edges->GetOutput());
4742                 Mapper->Update();
4743
4744                 int nb = Mapper->GetInput()->GetNumberOfCells();
4745                 //MESSAGE ( "nb : " << nb )
4746
4747                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4748                 for (; ite.More(); ite.Next())
4749                 {
4750                         vtkCell *StartEdge = Mapper->GetInput()->GetCell(ite.Key());
4751                         //MESSAGE( "DCQ : Edge Id = " << ite.Key())
4752                         int CellType = StartEdge->GetCellType();
4753                         //MESSAGE( "DCQ : Cell Type = " << CellType)
4754                         int nbPoints = StartEdge->GetNumberOfPoints();
4755
4756                         //MESSAGE( "DCQ : Nb Point = " << nbPoints)
4757                         if (nbPoints == 2)
4758                         {
4759                                 vtkUnstructuredGrid *StartUGrid =
4760                                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
4761
4762                                 vtkIdList *IdCells = vtkIdList::New();
4763                                 vtkIdList *IdPoints = StartEdge->GetPointIds();
4764                                 float p1[3];
4765                                 float p2[3];
4766
4767                                 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),
4768                                         p1);
4769                                 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),
4770                                         p2);
4771
4772                                 int idp1 = StartUGrid->FindPoint(p1);
4773                                 int idp2 = StartUGrid->FindPoint(p2);
4774
4775                                 StartUGrid->GetPointCells(idp1, IdCells);
4776
4777                                 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4778                                 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4779
4780                                 //MESSAGE ( " pt 0 : " << idp1 )
4781                                 //MESSAGE ( " pt 1 : " << idp2 )
4782
4783                                 vtkIdList *IdPts = vtkIdList::New();
4784                                 if (IdCells->GetNumberOfIds() >= 2)
4785                                 {
4786                                         int nbCells = IdCells->GetNumberOfIds();
4787                                         //MESSAGE ( " nbCells : " << nbCells )
4788                                         for (int j = 0; j < nbCells; j++)
4789                                         {
4790                                                 StartUGrid->GetCellPoints(IdCells->GetId(j), IdPts);
4791                                                 if (IdPts->IsId(idp2) == -1)
4792                                                 {
4793                                                         IdCells->DeleteId(IdCells->GetId(j));
4794                                                 }
4795                                         }
4796
4797                                         //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4798
4799                                         vtkIdList *IdPts0 = vtkIdList::New();
4800                                         vtkIdList *IdPts1 = vtkIdList::New();
4801
4802                                         if (IdCells->GetNumberOfIds() == 2)
4803                                         {
4804                                                 StartUGrid->GetCellPoints(IdCells->GetId(0), IdPts0);
4805                                                 StartUGrid->GetCellPoints(IdCells->GetId(1), IdPts1);
4806
4807                                                 //Create new faces
4808                                                 TColStd_MapOfInteger EndMapIndex;
4809                                                 for (int j = 0; j < 3; j++)
4810                                                 {
4811                                                         if (IdPts0->GetId(j) != idp1 &&
4812                                                                 IdPts0->GetId(j) != idp2)
4813                                                         {
4814                                                                 EndMapIndex.Add(IdPts0->GetId(j));
4815                                                         }
4816                                                         if (IdPts1->GetId(j) != idp1 &&
4817                                                                 IdPts1->GetId(j) != idp2)
4818                                                         {
4819                                                                 EndMapIndex.Add(IdPts1->GetId(j));
4820                                                         }
4821                                                 }
4822
4823                                                 bool MyAU = myAutomaticUpdate;
4824                                                 myAutomaticUpdate = false;
4825
4826                                                 EndMapIndex.Add(idp1);
4827                                                 TColStd_MapIteratorOfMapOfInteger ite1(EndMapIndex);
4828                                                 int i = 1;
4829                                                 while (ite1.More())
4830                                                 {
4831                                                         if (ite1.Key() == idp1)
4832                                                                 break;
4833                                                         i++;
4834                                                         ite1.Next();
4835                                                 }
4836                                                 bool reverse1 = (i == 2);
4837                                                 this->AddFace(aMesh, EndMapIndex, reverse1);
4838
4839                                                 EndMapIndex.Remove(idp1);
4840                                                 EndMapIndex.Add(idp2);
4841                                                 TColStd_MapIteratorOfMapOfInteger ite2(EndMapIndex);
4842                                                 i = 1;
4843                                                 while (ite2.More())
4844                                                 {
4845                                                         if (ite2.Key() == idp2)
4846                                                                 break;
4847                                                         i++;
4848                                                         ite2.Next();
4849                                                 }
4850                                                 bool reverse2 = (i == 2);
4851                                                 this->AddFace(aMesh, EndMapIndex,
4852                                                         !(reverse1 == reverse2));
4853
4854                                                 myAutomaticUpdate = MyAU;
4855                                                 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4856                                                 Mapper->Update();
4857                                                 //Remove old faces
4858                                                 TColStd_MapOfInteger StartMapIndex;
4859                                                 StartMapIndex.Add(IdCells->GetId(0));
4860                                                 StartMapIndex.Add(IdCells->GetId(1));
4861                                                 this->RemoveElements(aMesh, StartMapIndex);
4862
4863                                                 Mapper->Update();
4864                                         }
4865                                 }
4866                         }
4867                 }
4868
4869                 //      UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4870                 //      int nbCells = Mapper->GetInput()->GetNumberOfCells();
4871                 //      for ( int i = 0; i < nbCells; i++ ) {
4872                 //        UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4873                 //      }
4874
4875                 //      vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4876                 //      NewMapper->SetInput( UGrid );
4877                 //      NewMapper->Update();
4878
4879                 //      ac->DataSource = NewMapper->GetInput();
4880                 //      ac->SetMapper( NewMapper );
4881         }
4882         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4883         renWin->Render();
4884         QApplication::restoreOverrideCursor();
4885 }
4886
4887 //=============================================================================
4888 /*!
4889  *
4890  */
4891 //=============================================================================
4892 void SMESHGUI::AddEdges(SMESH_Actor * Mactor, int number,
4893         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4894 {
4895         QApplication::setOverrideCursor(Qt::waitCursor);
4896         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4897         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4898         int i = 1;
4899         int j = 1;
4900         while (i <= number)
4901         {
4902                 vtkIdList *Ids = vtkIdList::New();
4903                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
4904                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
4905                 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4906                 Mactor->AddElement(indexes[j - 1], id);
4907                 i++;
4908                 j = j + 3;
4909         }
4910         vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4911         EdgeMapper->SetInput(ugrid);
4912         Mactor->DataSource = EdgeMapper->GetInput();
4913         Mactor->SetMapper(EdgeMapper);
4914         QApplication::restoreOverrideCursor();
4915 }
4916
4917 //=============================================================================
4918 /*!
4919  *
4920  */
4921 //=============================================================================
4922 void SMESHGUI::AddEdge(SMESH_Actor * Mactor, int idedge, int idnode1,
4923         int idnode2)
4924 {
4925         QApplication::setOverrideCursor(Qt::waitCursor);
4926         MESSAGE("SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" <<
4927                 idnode2) vtkIdList *Ids = vtkIdList::New();
4928         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
4929         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
4930
4931         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4932         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4933         int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4934         Mactor->AddElement(idedge, id);
4935
4936         MESSAGE(" Edge VTK id " << id)
4937                 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4938         EdgeMapper->SetInput(ugrid);
4939         Mactor->DataSource = EdgeMapper->GetInput();
4940         Mactor->SetMapper(EdgeMapper);
4941         QApplication::restoreOverrideCursor();
4942 }
4943
4944 //=============================================================================
4945 /*!
4946  *
4947  */
4948 //=============================================================================
4949 void SMESHGUI::AddTriangles(SMESH_Actor * Mactor, int number,
4950         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4951 {
4952         MESSAGE("SMESHGUI::AddTriangles(number="<<number<<", indexes.length="
4953                 <<indexes.length()<<")");
4954
4955         QApplication::setOverrideCursor(Qt::waitCursor);
4956         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4957         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4958         int i = 1;
4959         int j = 1;
4960         while (i <= number)
4961         {
4962                 vtkIdList *Ids = vtkIdList::New();
4963                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
4964                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
4965                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
4966                 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4967                 Mactor->AddElement(indexes[j - 1], id);
4968                 i++;
4969                 j = j + 4;
4970         }
4971         vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4972         TriMapper->SetInput(ugrid);
4973         Mactor->DataSource = TriMapper->GetInput();
4974         Mactor->SetMapper(TriMapper);
4975         QApplication::restoreOverrideCursor();
4976 }
4977 void SMESHGUI::AddTriangle(SMESH_Actor * Mactor, int idtri, int idnode1,
4978         int idnode2, int idnode3)
4979 {
4980         QApplication::setOverrideCursor(Qt::waitCursor);
4981         vtkIdList *Ids = vtkIdList::New();
4982         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
4983         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
4984         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
4985
4986         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4987         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4988         int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4989         Mactor->AddElement(idtri, id);
4990
4991         vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4992         TriMapper->SetInput(ugrid);
4993         Mactor->DataSource = TriMapper->GetInput();
4994         Mactor->SetMapper(TriMapper);
4995         QApplication::restoreOverrideCursor();
4996 }
4997
4998 //=============================================================================
4999 /*!
5000  *
5001  */
5002 //=============================================================================
5003 void SMESHGUI::AddQuadrangles(SMESH_Actor * Mactor, int number,
5004         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5005 {
5006         QApplication::setOverrideCursor(Qt::waitCursor);
5007         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5008         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5009         int i = 1;
5010         int j = 1;
5011         while (i <= number)
5012         {
5013                 vtkIdList *Ids = vtkIdList::New();
5014                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5015                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5016                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5017                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5018                 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5019                 Mactor->AddElement(indexes[j - 1], id);
5020                 i++;
5021                 j = j + 5;
5022         }
5023         vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5024         QuadMapper->SetInput(ugrid);
5025         Mactor->DataSource = QuadMapper->GetInput();
5026         Mactor->SetMapper(QuadMapper);
5027         QApplication::restoreOverrideCursor();
5028 }
5029
5030 //=============================================================================
5031 /*!
5032  *
5033  */
5034 //=============================================================================
5035 void SMESHGUI::AddQuadrangle(SMESH_Actor * Mactor, int idquad, int idnode1,
5036         int idnode2, int idnode3, int idnode4)
5037 {
5038         QApplication::setOverrideCursor(Qt::waitCursor);
5039         vtkIdList *Ids = vtkIdList::New();
5040         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5041         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5042         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5043         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5044
5045         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5046         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5047         int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5048         Mactor->AddElement(idquad, id);
5049
5050         vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5051         QuadMapper->SetInput(ugrid);
5052         Mactor->DataSource = QuadMapper->GetInput();
5053         Mactor->SetMapper(QuadMapper);
5054         QApplication::restoreOverrideCursor();
5055 }
5056
5057 //=============================================================================
5058 /*!
5059  *
5060  */
5061 //=============================================================================
5062 void SMESHGUI::AddTetras(SMESH_Actor * Mactor, int number,
5063         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5064 {
5065         QApplication::setOverrideCursor(Qt::waitCursor);
5066         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5067         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5068         int i = 1;
5069         int j = 1;
5070         while (i <= number)
5071         {
5072                 vtkIdList *Ids = vtkIdList::New();
5073                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5074                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5075                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5076                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5077                 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5078                 Mactor->AddElement(indexes[j - 1], id);
5079                 i++;
5080                 j = j + 5;
5081         }
5082         vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5083         TetraMapper->SetInput(ugrid);
5084         Mactor->DataSource = TetraMapper->GetInput();
5085         Mactor->SetMapper(TetraMapper);
5086         QApplication::restoreOverrideCursor();
5087 }
5088
5089 //=============================================================================
5090 /*!
5091  *
5092  */
5093 //=============================================================================
5094 void SMESHGUI::AddTetra(SMESH_Actor * Mactor, int idtetra, int idnode1,
5095         int idnode2, int idnode3, int idnode4)
5096 {
5097         QApplication::setOverrideCursor(Qt::waitCursor);
5098         MESSAGE("SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" <<
5099                 idnode2 << ";" << idnode3 << ";" << idnode4) vtkIdList *Ids =
5100                 vtkIdList::New();
5101         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5102         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5103         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5104         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5105
5106         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5107         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5108         int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5109         Mactor->AddElement(idtetra, id);
5110
5111         MESSAGE(" Tetra VTK id " << id)
5112                 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5113         TetraMapper->SetInput(ugrid);
5114         Mactor->DataSource = TetraMapper->GetInput();
5115         Mactor->SetMapper(TetraMapper);
5116         QApplication::restoreOverrideCursor();
5117 }
5118
5119 //=============================================================================
5120 /*!
5121  *
5122  */
5123 //=============================================================================
5124 void SMESHGUI::AddHexaedres(SMESH_Actor * Mactor, int number,
5125         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5126 {
5127         QApplication::setOverrideCursor(Qt::waitCursor);
5128         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5129         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5130         int i = 1;
5131         int j = 1;
5132         while (i <= number)
5133         {
5134                 vtkIdList *Ids = vtkIdList::New();
5135                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5136                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5137                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5138                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5139                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 4]));
5140                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 5]));
5141                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 6]));
5142                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 7]));
5143                 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5144                 Mactor->AddElement(indexes[j - 1], id);
5145                 i++;
5146                 j = j + 9;
5147         }
5148         vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5149         HexaMapper->SetInput(ugrid);
5150         Mactor->DataSource = HexaMapper->GetInput();
5151         Mactor->SetMapper(HexaMapper);
5152         QApplication::restoreOverrideCursor();
5153 }
5154
5155 //=============================================================================
5156 /*!
5157  *
5158  */
5159 //=============================================================================
5160 void SMESHGUI::AddHexaedre(SMESH_Actor * Mactor, int idhexa, int idnode1,
5161         int idnode2, int idnode3, int idnode4, int idnode5, int idnode6,
5162         int idnode7, int idnode8)
5163 {
5164         QApplication::setOverrideCursor(Qt::waitCursor);
5165         MESSAGE("SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" <<
5166                 idnode2 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" <<
5167                 idnode6 << ";" << idnode7 << ";" << idnode8) vtkIdList *Ids =
5168                 vtkIdList::New();
5169         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5170         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5171         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5172         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5173         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode5));
5174         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode6));
5175         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode7));
5176         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode8));
5177
5178         //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5179         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5180         int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5181         Mactor->AddElement(idhexa, id);
5182
5183         MESSAGE(" Hexa VTK id " << id)
5184                 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5185         HexaMapper->SetInput(ugrid);
5186         Mactor->DataSource = HexaMapper->GetInput();
5187         Mactor->SetMapper(HexaMapper);
5188         QApplication::restoreOverrideCursor();
5189 }
5190
5191 //=====================================================================================
5192 // EXPORTED METHODS
5193 //=====================================================================================
5194 extern "C"
5195 {
5196         bool OnGUIEvent(int theCommandID, QAD_Desktop * parent)
5197         {
5198                 return SMESHGUI::OnGUIEvent(theCommandID, parent);
5199         }
5200
5201         bool OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
5202                 QAD_StudyFrame * studyFrame)
5203         {
5204                 return SMESHGUI::OnKeyPress(pe, parent, studyFrame);
5205         }
5206
5207         bool OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
5208                 QAD_StudyFrame * studyFrame)
5209         {
5210                 return SMESHGUI::OnMousePress(pe, parent, studyFrame);
5211         }
5212
5213         bool OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
5214                 QAD_StudyFrame * studyFrame)
5215         {
5216                 return SMESHGUI::OnMouseMove(pe, parent, studyFrame);
5217         }
5218
5219         bool SetSettings(QAD_Desktop * parent)
5220         {
5221                 return SMESHGUI::SetSettings(parent);
5222         }
5223
5224         bool customPopup(QAD_Desktop * parent, QPopupMenu * popup,
5225                 const QString & theContext, const QString & theParent,
5226                 const QString & theObject)
5227         {
5228                 return SMESHGUI::CustomPopup(parent, popup, theContext, theParent,
5229                         theObject);
5230         }
5231
5232         void definePopup(QString & theContext, QString & theParent,
5233                 QString & theObject)
5234         {
5235                 SMESHGUI::DefinePopup(theContext, theParent, theObject);
5236         }
5237
5238         bool activeStudyChanged(QAD_Desktop * parent)
5239         {
5240                 SMESHGUI::activeStudyChanged(parent);
5241         }
5242
5243         void buildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
5244         {
5245                 SMESHGUI::BuildPresentation(theIO);
5246         }
5247
5248         void supportedViewType(int *buffer, int bufferSize)
5249         {
5250                 if (!buffer || !bufferSize)
5251                         return;
5252                 buffer[0] = (int)VIEW_VTK;
5253         }
5254
5255 }
5256
5257 //=============================================================================
5258 /*!
5259  *
5260  */
5261 //=============================================================================
5262 void SMESHGUI::ViewNodes()
5263 {
5264         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5265                 return;
5266
5267         EraseSimulationActors();
5268         mySimulationActors = vtkActorCollection::New();
5269         vtkRenderer *theRenderer =
5270                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5271                 getRightFrame()->getViewFrame())->getRenderer();
5272         vtkActorCollection *theActors = theRenderer->GetActors();
5273         theActors->InitTraversal();
5274         vtkActor *ac = theActors->GetNextActor();
5275         while (!(ac == NULL))
5276         {
5277                 if (ac->IsA("SMESH_Actor"))
5278                 {
5279                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
5280                         if (anActor->GetVisibility() == 1)
5281                         {
5282                                 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5283                                 gf->SetInput(anActor->DataSource);
5284                                 vtkMaskPoints *verts = vtkMaskPoints::New();
5285                                 verts->SetInput(gf->GetOutput());
5286                                 verts->GenerateVerticesOn();
5287                                 verts->SetOnRatio(1);
5288
5289                                 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
5290                                 vertMapper->SetInput(verts->GetOutput());
5291                                 vertMapper->ScalarVisibilityOff();
5292
5293                                 vtkActor *vertActor = vtkActor::New();
5294                                 vertActor->SetMapper(vertMapper);
5295
5296                                 float r, g, b;
5297                                 anActor->GetNodeColor(r, g, b);
5298                                 vertActor->GetProperty()->SetColor(r, g, b);
5299
5300                                 vertActor->GetProperty()->SetPointSize(anActor->GetNodeSize());
5301
5302                                 vertActor->PickableOff();
5303
5304                                 mySimulationActors->AddItem(vertActor);
5305                                 theRenderer->AddActor(vertActor);
5306                         }
5307                 }
5308                 ac = theActors->GetNextActor();
5309         }
5310
5311         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5312         renWin->Render();
5313 }
5314
5315 //=============================================================================
5316 /*!
5317  *
5318  */
5319 //=============================================================================
5320 void SMESHGUI::Control(int theCommandID)
5321 {
5322         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5323                 return;
5324
5325         QApplication::setOverrideCursor(Qt::waitCursor);
5326         DisplayScalarBar(false);
5327
5328         vtkDoubleArray *scalars = vtkDoubleArray::New();
5329         scalars->SetNumberOfComponents(1);
5330
5331         vtkDataSetMapper *meshMapper = 0;
5332         SALOME_Selection *Sel =
5333                 SALOME_Selection::Selection(myActiveStudy->getSelection());
5334         int nbSel = Sel->IObjectCount();
5335         Standard_Boolean result;
5336         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
5337         SMESH_Actor *MeshActor =
5338                 FindActorByEntry(IObject->getEntry(), result, true);
5339
5340         // Mesh may be not updated after Compute
5341         if (!MeshActor->DataSource || !MeshActor->GetMapper())
5342         {
5343                 QApplication::restoreOverrideCursor();
5344                 return;
5345         }
5346
5347         vtkDataSet *aDataSet = MeshActor->DataSource;
5348         typedef double (*TScalarFun) (vtkCell * theCell);
5349         TScalarFun aScalarFun;
5350         if (result)
5351         {
5352                 QString type;
5353                 switch (theCommandID)
5354                 {
5355                 case 6001:
5356                 {
5357                         type = tr("SMESH_CONTROL_LENGTH_EDGES");
5358                         aDataSet = MeshActor->EdgeDevice->GetMapper()->GetInput();
5359                         aScalarFun = &(SMESHGUI_ComputeScalarValue::LengthEdges);
5360                         MESSAGE(" init minimum length " << aDataSet->GetNumberOfCells());
5361                         if (MeshActor->getDisplayMode() != 0)
5362                                 ChangeRepresentation(MeshActor, 1);     // limitation; in Wireframe, colored edges are not visible
5363                         break;
5364                 }
5365                 case 6011:
5366                 {
5367                         type = tr("SMESH_CONTROL_AREA_ELEMENTS");
5368                         aScalarFun = &(SMESHGUI_ComputeScalarValue::AreaElements);
5369                         if (MeshActor->getDisplayMode() != 1)
5370                                 ChangeRepresentation(MeshActor, 1);
5371                         break;
5372                 }
5373                 case 6012:
5374                 {
5375                         type = tr("SMESH_CONTROL_TAPER_ELEMENTS");
5376                         aScalarFun = &(SMESHGUI_ComputeScalarValue::Taper);
5377                         break;
5378                 }
5379                 case 6013:
5380                 {
5381                         type = tr("SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
5382                         aScalarFun = &(SMESHGUI_ComputeScalarValue::AspectRatio);
5383                         if (MeshActor->getDisplayMode() != 1)
5384                                 ChangeRepresentation(MeshActor, 1);
5385                         break;
5386                 }
5387                 case 6014:
5388                 {
5389                         type = tr("SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
5390                         aScalarFun = &(SMESHGUI_ComputeScalarValue::MinimumAngle);
5391                         if (MeshActor->getDisplayMode() != 1)
5392                                 ChangeRepresentation(MeshActor, 1);
5393                         break;
5394                 }
5395                 case 6015:
5396                 {
5397                         type = tr("SMESH_CONTROL_WARP_ELEMENTS");
5398                         aScalarFun = &(SMESHGUI_ComputeScalarValue::Warp);
5399                         break;
5400                 }
5401                 case 6016:
5402                 {
5403                         type = tr("SMESH_CONTROL_SKEW_ELEMENTS");
5404                         aScalarFun = &(SMESHGUI_ComputeScalarValue::Skew);
5405                         break;
5406                 }
5407                 }
5408
5409                 for (int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++)
5410                         scalars->InsertTuple1(i, aScalarFun(aDataSet->GetCell(i)));
5411
5412                 float range[2];
5413                 scalars->GetRange(range);
5414
5415                 vtkLookupTable *wat = vtkLookupTable::New();
5416                 wat->SetRange(range);
5417                 wat->Build();
5418
5419                 scalars->SetLookupTable(wat);
5420
5421                 if (!meshMapper)
5422                         meshMapper = (vtkDataSetMapper *) (MeshActor->getMapper());
5423                 meshMapper->SetScalarModeToUseCellData();
5424                 MeshActor->DataSource->GetCellData()->SetScalars(scalars);
5425                 meshMapper->SetScalarRange(range);
5426                 meshMapper->ScalarVisibilityOn();
5427
5428                 vtkScalarBarActor *aScalarBar = GetScalarBar();
5429                 if (aScalarBar == NULL)
5430                 {
5431                         aScalarBar = vtkScalarBarActor::New();
5432                         QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
5433                         QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
5434                         QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
5435                         QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
5436                         QString Orientation =
5437                                 QAD_CONFIG->getSetting("ScalarBar:Orientation");
5438                         float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
5439                         float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
5440                         int NumberOfLabels =
5441                                 QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
5442                         int NumberOfColors =
5443                                 QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
5444
5445                         SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily,
5446                                 Orientation, Width, Height, NumberOfColors, NumberOfLabels);
5447                         vtkRenderer *theRenderer =
5448                                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5449                                 getRightFrame()->getViewFrame())->getRenderer();
5450                         theRenderer->AddActor2D(aScalarBar);
5451                 }
5452                 aScalarBar->SetLookupTable(wat);
5453                 aScalarBar->SetTitle(type.latin1());
5454
5455                 scalars->Delete();
5456                 //    wat->Delete();
5457                 DisplayScalarBar(true);
5458         }
5459         QApplication::restoreOverrideCursor();
5460 }
5461
5462 //=============================================================================
5463 /*!
5464  *
5465  */
5466 //=============================================================================
5467 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor * theScalarBar,
5468         QString Bold, QString Italic,
5469         QString Shadow, QString FontFamily,
5470         QString Orientation, float Width, float Height, int NbColors, int NbLabels)
5471 {
5472         if (Bold.isNull() || Bold.isEmpty() || (Bold.compare("true") == 0))
5473                 theScalarBar->BoldOn();
5474         else
5475                 theScalarBar->BoldOff();
5476
5477         if (Italic.isNull() || Italic.isEmpty() || (Italic.compare("true") == 0))
5478                 theScalarBar->ItalicOn();
5479         else
5480                 theScalarBar->ItalicOff();
5481
5482         if (Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare("true") == 0))
5483                 theScalarBar->ShadowOn();
5484         else
5485                 theScalarBar->ShadowOff();
5486
5487         if (FontFamily.compare("Arial") == 0)
5488                 theScalarBar->SetFontFamilyToArial();
5489         else if (FontFamily.compare("Courier") == 0)
5490                 theScalarBar->SetFontFamilyToCourier();
5491         else if (FontFamily.compare("Times") == 0)
5492                 theScalarBar->SetFontFamilyToTimes();
5493         else
5494                 theScalarBar->SetFontFamilyToArial();
5495
5496         if (Orientation.isNull() || Orientation.isEmpty() ||
5497                 (Orientation.compare("Vertical") == 0))
5498                 theScalarBar->SetOrientationToVertical();
5499         else
5500                 theScalarBar->SetOrientationToHorizontal();
5501
5502         theScalarBar->SetWidth((Width == 0) ? 0.17 : Width);
5503         theScalarBar->SetHeight((Height == 0) ? 0.8 : Height);
5504
5505         theScalarBar->SetNumberOfLabels((NbLabels == 0) ? 5 : NbLabels);
5506         theScalarBar->SetMaximumNumberOfColors((NbColors == 0) ? 64 : NbColors);
5507 }
5508
5509 //=============================================================================
5510 /*!
5511  *
5512  */
5513 //=============================================================================
5514 void SMESHGUI::DisplayScalarBar(bool visibility)
5515 {
5516         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5517                 return;
5518
5519         vtkRenderer *theRenderer =
5520                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5521                 getRightFrame()->getViewFrame())->getRenderer();
5522         vtkScalarBarActor *aScalarBar = GetScalarBar();
5523
5524         if (aScalarBar == NULL)
5525         {
5526                 MESSAGE("myScalarBar is NULL");
5527                 return;
5528         }
5529
5530         if (visibility)
5531                 aScalarBar->VisibilityOn();
5532         else
5533         {
5534                 aScalarBar->VisibilityOff();
5535                 //Turn off mesh coloring (influences on all views)
5536                 vtkActorCollection *actorList = theRenderer->GetActors();
5537                 actorList->InitTraversal();
5538                 vtkActor *ac = actorList->GetNextActor();
5539                 while (ac != NULL)
5540                 {
5541                         if (ac->GetMapper() != NULL)
5542                         {
5543                                 ac->GetMapper()->ScalarVisibilityOff();
5544                         }
5545                         ac = actorList->GetNextActor();
5546                 }
5547                 // Turn off ScalarBar in all views
5548                 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
5549                  * for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
5550                  * if (aFrame->getTypeView() == VIEW_VTK) {
5551                  * vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
5552                  * vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
5553                  * actor2DList->InitTraversal();
5554                  * vtkActor2D* aActor2d =  actor2DList->GetNextActor2D();
5555                  * while (aActor2d != NULL) {
5556                  * if (aActor2d->IsA("vtkScalarBarActor")) {
5557                  * aActor2d->VisibilityOff();
5558                  * break;
5559                  * }
5560                  * actor2DList->GetNextActor2D();
5561                  * }
5562                  * }
5563                  * } */
5564         }
5565         myActiveStudy->update3dViewers();
5566 }
5567
5568 //=============================================================================
5569 /*!
5570  *
5571  */
5572 //=============================================================================
5573 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
5574 {
5575         vtkScalarBarActor *aScalarBar = GetScalarBar();
5576         if (aScalarBar == NULL)
5577         {
5578                 MESSAGE("myScalarBar is NULL");
5579                 return;
5580         }
5581         DisplayScalarBar(false);
5582
5583         aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
5584         vtkRenderer *aRenderer =
5585                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5586                 getRightFrame()->getViewFrame())->getRenderer();
5587         vtkActorCollection *aActorList = aRenderer->GetActors();
5588         aActorList->InitTraversal();
5589         vtkActor *aActor = aActorList->GetNextActor();
5590         while (aActor != NULL)
5591         {
5592                 if (aActor->IsA("SMESH_Actor"))
5593                 {
5594                         SMESH_Actor *aMeshActor = SMESH_Actor::SafeDownCast(aActor);
5595                         vtkDataSetMapper *aMeshMapper =
5596                                 (vtkDataSetMapper *) (aMeshActor->getMapper());
5597                         if ((aMeshMapper != NULL))
5598                         {
5599                                 aMeshMapper->SetScalarRange(MinRange, MaxRange);
5600                                 aMeshMapper->ScalarVisibilityOn();
5601                         }
5602                 }
5603                 aActor = aActorList->GetNextActor();
5604         }
5605         DisplayScalarBar(true);
5606 }
5607
5608 //=============================================================================
5609 /*!
5610  *
5611  */
5612 //=============================================================================
5613 void SMESHGUI::SetDisplaySettings()
5614 {
5615         EmitSignalDeactivateDialog();
5616         SMESHGUI_Preferences_ColorDlg *aDlg =
5617                 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
5618
5619         QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
5620         QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
5621         QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
5622         QColor color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5623         aDlg->SetColor(1, color);
5624
5625         SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
5626         SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
5627         SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
5628         color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5629         aDlg->SetColor(2, color);
5630
5631         SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5632         SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5633         SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5634         color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5635         aDlg->SetColor(3, color);
5636
5637         QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
5638         QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
5639         QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
5640         color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
5641         aDlg->SetColor(4, color);
5642
5643         QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
5644         aDlg->SetIntValue(1, intValue.toInt());
5645         intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
5646         aDlg->SetIntValue(2, intValue.toInt());
5647         intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
5648         aDlg->SetIntValue(3, intValue.toInt());
5649
5650         if (aDlg->exec())
5651         {
5652                 QColor colorFill = aDlg->GetColor(1);
5653                 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
5654                 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen",
5655                         colorFill.green());
5656                 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
5657
5658                 QColor colorOutline = aDlg->GetColor(2);
5659                 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed",
5660                         colorOutline.red());
5661                 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen",
5662                         colorOutline.green());
5663                 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue",
5664                         colorOutline.blue());
5665
5666                 QColor colorNode = aDlg->GetColor(3);
5667                 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
5668                 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen",
5669                         colorNode.green());
5670                 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
5671
5672                 QColor colorBackFace = aDlg->GetColor(4);
5673                 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed",
5674                         colorBackFace.red());
5675                 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen",
5676                         colorBackFace.green());
5677                 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue",
5678                         colorBackFace.blue());
5679
5680                 int width = aDlg->GetIntValue(1);
5681                 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
5682
5683                 int nodes_size = aDlg->GetIntValue(2);
5684                 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
5685
5686                 int shrink_coeff = aDlg->GetIntValue(3);
5687                 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
5688         }
5689
5690         delete aDlg;
5691 }
5692
5693 //=======================================================================
5694 // function : Parameter()
5695 // purpose  : return a parameter (double) from a dialog box
5696 //
5697 //  aValue     : is a double used as a default value displayed
5698 //  aLabel     : is the title for aValue1
5699 //  aTitle     : is the main title
5700 //  bottom     : maximum value to be entered
5701 //  top        : minimum value to be entered
5702 //  decimals   : number of decimals
5703 //=======================================================================
5704 double SMESHGUI::Parameter(Standard_Boolean & res,
5705         const double aValue,
5706         const char *aLabel,
5707         const char *aTitle,
5708         const double bottom, const double top, const int decimals)
5709 {
5710         SMESHGUI_aParameterDlg *Dialog =
5711                 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5712                 aTitle,
5713                 aLabel,
5714                 bottom, top, decimals,
5715                 TRUE);
5716         Dialog->setValue(aValue);
5717         double X = 0.0;
5718         res = (Dialog->exec() == QDialog::Accepted);
5719         if (res)
5720                 X = Dialog->getDblValue();
5721         return X;
5722 }
5723
5724 //=======================================================================
5725 // function : Parameter()
5726 // purpose  : return a parameter (int) from a dialog box
5727 //
5728 //  aValue     : is a int used as a default value displayed
5729 //  aLabel     : is the title for aValue1
5730 //  aTitle     : is the main title
5731 //  bottom     : maximum value to be entered
5732 //  top        : minimum value to be entered
5733 //=======================================================================
5734 int SMESHGUI::Parameter(Standard_Boolean & res,
5735         const int aValue,
5736         const char *aLabel, const char *aTitle, const int bottom, const int top)
5737 {
5738         SMESHGUI_aParameterDlg *Dialog =
5739                 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5740                 aTitle,
5741                 aLabel,
5742                 bottom, top,
5743                 TRUE);
5744         Dialog->setValue(aValue);
5745         int X = 0;
5746         res = (Dialog->exec() == QDialog::Accepted);
5747         if (res)
5748                 X = Dialog->getIntValue();
5749         return X;
5750 }
5751
5752 //=============================================================================
5753 /*!
5754  *
5755  */
5756 //=============================================================================
5757 void SMESHGUI::DisplayEdges(SMESH_Actor * ac, bool visibility)
5758 {
5759         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5760                 return;
5761         if (ac->DataSource == NULL || ac->GetMapper() == NULL)
5762                 return;
5763
5764         vtkGeometryFilter *gf = vtkGeometryFilter::New();
5765         gf->SetInput(ac->DataSource);
5766         vtkFeatureEdges *edges = vtkFeatureEdges::New();
5767         edges->SetInput(gf->GetOutput());
5768         edges->BoundaryEdgesOn();
5769         edges->ManifoldEdgesOn();
5770
5771         vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5772         edgeMapper->SetInput(edges->GetOutput());
5773         edgeMapper->ScalarVisibilityOff();
5774
5775         vtkRenderer *theRenderer =
5776                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5777                 getRightFrame()->getViewFrame())->getRenderer();
5778         vtkActorCollection *actorList = theRenderer->GetActors();
5779
5780         int test = actorList->IsItemPresent(ac->EdgeDevice);
5781         if (test == 0)
5782         {
5783                 vtkProperty *prop = vtkProperty::New();
5784                 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5785                         toFloat() / 255.,
5786                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5787                         toFloat() / 255.,
5788                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5789                         255.);
5790                 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5791                         toInt());
5792                 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5793                         toInt());
5794                 ac->EdgeDevice->SetProperty(prop);
5795                 ac->SetEdgeColor(QAD_CONFIG->
5796                         getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5797                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5798                         toFloat() / 255.,
5799                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5800                         255.);
5801                 ac->EdgeDevice->SetMapper(edgeMapper);
5802
5803                 theRenderer->AddActor(ac->EdgeDevice);
5804         }
5805         else
5806         {
5807                 ac->EdgeDevice->SetMapper(edgeMapper);
5808                 edgeMapper->Update();
5809         }
5810
5811         vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5812         shrink->SetInput(ac->DataSource);
5813         shrink->SetShrinkFactor(ac->GetShrinkFactor());
5814         vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5815         Shrinkgf->SetInput(shrink->GetOutput());
5816         vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5817         ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5818         ShrinkEdges->BoundaryEdgesOn();
5819         ShrinkEdges->ManifoldEdgesOn();
5820
5821         vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5822         ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5823         ShrinkEdgeMapper->ScalarVisibilityOff();
5824
5825         test = actorList->IsItemPresent(ac->EdgeShrinkDevice);
5826         if (test == 0)
5827         {
5828                 vtkProperty *prop = vtkProperty::New();
5829                 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5830                         toFloat() / 255.,
5831                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5832                         toFloat() / 255.,
5833                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5834                         255.);
5835                 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5836                         toInt());
5837                 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5838                         toInt());
5839                 ac->EdgeShrinkDevice->SetProperty(prop);
5840                 ac->SetEdgeColor(QAD_CONFIG->
5841                         getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5842                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5843                         toFloat() / 255.,
5844                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5845                         255.);
5846                 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5847
5848                 theRenderer->AddActor(ac->EdgeShrinkDevice);
5849         }
5850         else
5851         {
5852                 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5853                 ShrinkEdgeMapper->Update();
5854         }
5855
5856         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5857         renWin->Render();
5858 }
5859
5860 //=============================================================================
5861 /*!
5862  *
5863  */
5864 //=============================================================================
5865 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5866 {
5867         SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh(aMesh);
5868         SALOMEDS::GenericAttribute_var anAttr;
5869         SALOMEDS::AttributeName_var aName;
5870         if (!aSO_M->_is_nil())
5871         {
5872                 if (aSO_M->FindAttribute(anAttr, "AttributeName"))
5873                 {
5874                         aName = SALOMEDS::AttributeName::_narrow(anAttr);
5875                         Standard_Boolean result;
5876                         SMESH_Actor *MeshActor =
5877                                 smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5878                         if (!result)
5879                         {
5880                                 SMESH_Actor *amesh = SMESH_Actor::New();
5881                                 Handle(SALOME_InteractiveObject) IO =
5882                                         new SALOME_InteractiveObject(aSO_M->GetID(), "MESH",
5883                                         aName->Value());
5884                                 amesh->setIO(IO);
5885                                 amesh->setName(aName->Value());
5886                                 DisplayActor(amesh, false);
5887                         }
5888                 }
5889         }
5890 }
5891
5892 //=============================================================================
5893 /*!
5894  *
5895  */
5896 //=============================================================================
5897 void SMESHGUI::Update()
5898 {
5899         MESSAGE("SMESHGUI::Update");
5900         if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
5901         {                                                       //VTK
5902                 vtkRenderer *theRenderer =
5903                         ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5904                         getRightFrame()->getViewFrame())->getRenderer();
5905
5906                 SALOME_Selection *Sel =
5907                         SALOME_Selection::Selection(myActiveStudy->getSelection());
5908                 int nbSel = Sel->IObjectCount();
5909                 if (nbSel == 0)
5910                 {
5911                         vtkActorCollection *actorList = theRenderer->GetActors();
5912                         actorList->InitTraversal();
5913                         vtkActor *ac = actorList->GetNextActor();
5914                         while (!(ac == NULL))
5915                         {
5916                                 if (ac->IsA("SMESH_Actor"))
5917                                 {
5918                                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
5919                                         if (anActor->hasIO())
5920                                         {
5921                                                 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5922                                                 Update(IO);
5923                                         }
5924                                 }
5925                                 ac = actorList->GetNextActor();
5926                         }
5927                 }
5928                 else
5929                 {
5930                         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
5931                         for (; It.More(); It.Next())
5932                         {
5933                                 Handle(SALOME_InteractiveObject) IO = It.Value();
5934                                 Update(IO);
5935                         }
5936                 }
5937                 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5938                 renWin->Render();
5939         }
5940         QApplication::restoreOverrideCursor();
5941 }
5942
5943 //=============================================================================
5944 /*!
5945  *
5946  */
5947 //=============================================================================
5948 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject) & IO)
5949 {
5950         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5951                 return;
5952
5953         if (IO->hasEntry())
5954         {
5955                 Standard_Boolean res;
5956                 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh(IO, res);
5957                 if (res)
5958                 {
5959                         SMESH_Actor *ac = FindActorByEntry(IO->getEntry(), res, false);
5960                         if (res)
5961                         {
5962                                 // Check whether the actor belongs to the active view
5963                                 VTKViewer_RenderWindowInteractor *rwInter =
5964                                         ((VTKViewer_ViewFrame *) myActiveStudy->
5965                                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
5966                                         getRWInteractor();
5967
5968                                 ac = ReadScript(aMesh);
5969                                 // The actor belongs to inactive view -> create a copy and display it in the active view
5970                                 if (!rwInter->isInViewer(IO))
5971                                 {
5972                                         SMESH_Actor *acCopy = SMESH_Actor::New();
5973                                         acCopy->ShallowCopy(ac);
5974                                         ac=acCopy;
5975                                 }
5976
5977                                 if (ac != NULL)
5978                                 {
5979 #ifdef TRACE
5980                                         Dump(ac);
5981 #endif
5982                                         DisplayActor(ac);
5983                                         DisplayEdges(ac);
5984                                         smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
5985                                 }
5986                         }
5987                 }
5988         }
5989 }
5990
5991 //=============================================================================
5992 /*!
5993  *
5994  */
5995 //=============================================================================
5996 vtkActor *SMESHGUI::SimulationMoveNode(SMESH_Actor * Mactor, int idnode)
5997 {
5998         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5999                 return NULL;
6000
6001         mySimulationActors = vtkActorCollection::New();
6002         vtkRenderer *theRenderer =
6003                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6004                 getRightFrame()->getViewFrame())->getRenderer();
6005
6006         vtkUnstructuredGrid *ugrid =
6007                 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
6008         vtkIdList *IdCells = vtkIdList::New();
6009         ugrid->GetPointCells(idnode, IdCells);
6010
6011         vtkPoints *Pts = vtkPoints::New();
6012         Pts = ugrid->GetPoints();
6013
6014         vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
6015         ugridSimulation->SetPoints(Pts);
6016         vtkIdList *IdPts = vtkIdList::New();
6017         for (int j = 0; j < IdCells->GetNumberOfIds(); j++)
6018         {
6019                 ugrid->GetCellPoints(IdCells->GetId(j), IdPts);
6020                 ugridSimulation->InsertNextCell(ugrid->GetCellType(IdCells->GetId(j)),
6021                         IdPts);
6022         }
6023
6024         vtkProperty *prop = vtkProperty::New();
6025         prop->SetColor(1., 0., 0.);
6026         prop->SetRepresentationToWireframe();
6027
6028         int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
6029         if (Edgewidth == 0)
6030                 Edgewidth = 1;
6031         prop->SetLineWidth(Edgewidth + 1);
6032
6033         vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6034         Mapper->SetInput(ugridSimulation);
6035         vtkActor *ac = vtkActor::New();
6036         ac->SetMapper(Mapper);
6037         ac->SetProperty(prop);
6038
6039         ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
6040         ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
6041
6042         mySimulationActors->AddItem(ac);
6043         theRenderer->AddActor(ac);
6044
6045         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6046         renWin->Render();
6047
6048         return ac;
6049 }
6050
6051 //=============================================================================
6052 /*!
6053  *
6054  */
6055 //=============================================================================
6056 void SMESHGUI::DisplaySimulationNode(SMESH::SMESH_Mesh_ptr aMesh, float x,
6057         float y, float z)
6058 {
6059         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6060                 return;
6061
6062         EraseSimulationActors();
6063         mySimulationActors = vtkActorCollection::New();
6064         vtkRenderer *theRenderer =
6065                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6066                 getRightFrame()->getViewFrame())->getRenderer();
6067         Standard_Boolean result;
6068         SMESH_Actor *ac = FindActor(aMesh, result, true);
6069
6070         if (result)
6071         {
6072                 vtkUnstructuredGrid *ugrid =
6073                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6074                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6075
6076                 vtkPoints *Pts = ugrid->GetPoints();
6077                 vtkPoints *newPts = vtkPoints::New();
6078                 int nbPts = Pts->GetNumberOfPoints();
6079                 for (int i = 0; i < nbPts; i++)
6080                 {
6081                         newPts->InsertPoint(i, Pts->GetPoint(i));
6082                 }
6083
6084                 newugrid->SetPoints(newPts);
6085                 newugrid->GetPoints()->InsertNextPoint(x, y, z);
6086
6087                 vtkMaskPoints *verts = vtkMaskPoints::New();
6088                 verts->SetInput(newugrid);
6089                 verts->SetGenerateVertices(1);
6090                 verts->SetOnRatio(1);
6091
6092                 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
6093                 vertMapper->SetInput(verts->GetOutput());
6094                 vertMapper->ScalarVisibilityOff();
6095
6096                 vtkActor *node = vtkActor::New();
6097                 node->SetMapper(vertMapper);
6098
6099                 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
6100                 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
6101                 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
6102                 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
6103                 if (!nodecolor.isValid())
6104 //       nodecolor = QColor(0.,1.,0.);
6105                         nodecolor = QColor(0, 1, 0);
6106
6107                 node->GetProperty()->SetColor(float (nodecolor.red()) / 255.,
6108                         float (nodecolor.green()) / 255., float (nodecolor.blue()) / 255.);
6109
6110                 int intValue =
6111                         QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
6112                 if (intValue < 1)
6113                         intValue == 1;
6114
6115                 node->GetProperty()->SetPointSize(intValue);
6116
6117                 node->VisibilityOn();
6118
6119                 mySimulationActors->AddItem(node);
6120                 theRenderer->AddActor(node);
6121         }
6122
6123         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6124         renWin->Render();
6125 }
6126
6127 //=============================================================================
6128 /*!
6129  *
6130  */
6131 //=============================================================================
6132 void SMESHGUI::DisplaySimulationMoveNode(vtkActor * ac, int idnode, float x,
6133         float y, float z)
6134 {
6135         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6136                 return;
6137
6138         vtkRenderer *theRenderer =
6139                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6140                 getRightFrame()->getViewFrame())->getRenderer();
6141         float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
6142         pt[0] = x;
6143         pt[1] = y;
6144         pt[2] = z;
6145
6146         ac->GetMapper()->ImmediateModeRenderingOn();
6147         ac->GetProperty()->SetRepresentationToWireframe();
6148
6149         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6150
6151         renWin->Render();
6152 }
6153
6154 //=============================================================================
6155 /*!
6156  *
6157  */
6158 //=============================================================================
6159 void SMESHGUI::MoveNode(SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x,
6160         float y, float z)
6161 {
6162         Standard_Boolean result;
6163
6164         SMESH_Actor *MeshActor = FindActor(aMesh, result, true);
6165         if (result)
6166         {
6167         }
6168 }
6169
6170 //=============================================================================
6171 /*!
6172  *
6173  */
6174 //=============================================================================
6175 void SMESHGUI::ScalarVisibilityOff()
6176 {
6177         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6178                 return;
6179
6180         vtkRenderer *theRenderer =
6181                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6182                 getRightFrame()->getViewFrame())->getRenderer();
6183         vtkActorCollection *actorList = theRenderer->GetActors();
6184
6185         actorList->InitTraversal();
6186         vtkActor *ac = actorList->GetNextActor();
6187         while (!(ac == NULL))
6188         {
6189                 if (ac->IsA("SMESH_Actor"))
6190                 {
6191                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
6192                         if (anActor->GetVisibility() == 1)
6193                         {
6194                                 vtkDataSetMapper *meshMapper =
6195                                         (vtkDataSetMapper *) (anActor->getMapper());
6196                                 meshMapper->ScalarVisibilityOff();
6197                                 meshMapper->SetInput(anActor->DataSource);
6198                                 ChangeRepresentation(anActor, anActor->getDisplayMode());
6199                         }
6200                 }
6201                 ac = actorList->GetNextActor();
6202         }
6203
6204         theRenderer->Render();
6205 }
6206
6207 //=============================================================================
6208 /*!
6209  *
6210  */
6211 //=============================================================================
6212 void SMESHGUI::DisplaySimulationEdge(SMESH::SMESH_Mesh_ptr aMesh,
6213         const TColStd_MapOfInteger & MapIndex)
6214 {
6215         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6216                 return;
6217
6218         EraseSimulationActors();
6219         mySimulationActors = vtkActorCollection::New();
6220         vtkRenderer *theRenderer =
6221                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6222                 getRightFrame()->getViewFrame())->getRenderer();
6223         Standard_Boolean result;
6224         SMESH_Actor *ac = FindActor(aMesh, result, true);
6225         if (result)
6226         {
6227                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6228                 int idNodes[2];
6229                 int pts[2];
6230                 int i = 0;
6231                 vtkIdList *Ids = vtkIdList::New();
6232                 for (; ite.More(); ite.Next())
6233                 {
6234                         idNodes[i] = ite.Key();
6235                         i++;
6236                 }
6237
6238                 Ids->InsertId(0, idNodes[0]);
6239                 pts[0] = idNodes[0];
6240                 Ids->InsertId(1, idNodes[1]);
6241                 pts[1] = idNodes[1];
6242
6243                 vtkUnstructuredGrid *ugrid =
6244                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6245                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6246                 newugrid->SetPoints(ugrid->GetPoints());
6247                 newugrid->InsertNextCell(VTK_LINE, 2, pts);
6248
6249                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6250                 Mapper->SetInput(newugrid);
6251                 Mapper->Update();
6252
6253                 vtkActor *edge = vtkActor::New();
6254                 edge->SetMapper(Mapper);
6255                 edge->SetProperty(ac->GetProperty());
6256                 edge->SetBackfaceProperty(ac->GetBackfaceProperty());
6257                 edge->VisibilityOn();
6258                 mySimulationActors->AddItem(edge);
6259                 theRenderer->AddActor(edge);
6260         }
6261
6262         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6263         renWin->Render();
6264 }
6265
6266 //=============================================================================
6267 /*!
6268  *
6269  */
6270 //=============================================================================
6271 void SMESHGUI::DisplaySimulationTriangle(SMESH::SMESH_Mesh_ptr aMesh,
6272         const TColStd_MapOfInteger & MapIndex, bool reverse)
6273 {
6274         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6275                 return;
6276
6277         EraseSimulationActors();
6278         mySimulationActors = vtkActorCollection::New();
6279         vtkRenderer *theRenderer =
6280                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6281                 getRightFrame()->getViewFrame())->getRenderer();
6282         Standard_Boolean result;
6283         SMESH_Actor *ac = FindActor(aMesh, result, true);
6284         if (result)
6285         {
6286                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6287                 int idNodes[3];
6288                 int pts[3];
6289                 int i = 0;
6290                 vtkIdList *Ids = vtkIdList::New();
6291                 for (; ite.More(); ite.Next())
6292                 {
6293                         idNodes[i] = ite.Key();
6294                         i++;
6295                 }
6296
6297                 if (reverse)
6298                 {
6299                         Ids->InsertId(0, idNodes[2]);
6300                         pts[0] = idNodes[2];
6301                         Ids->InsertId(1, idNodes[1]);
6302                         pts[1] = idNodes[1];
6303                         Ids->InsertId(2, idNodes[0]);
6304                         pts[2] = idNodes[0];
6305                 }
6306                 else
6307                 {
6308                         Ids->InsertId(0, idNodes[0]);
6309                         pts[0] = idNodes[0];
6310                         Ids->InsertId(1, idNodes[1]);
6311                         pts[1] = idNodes[1];
6312                         Ids->InsertId(2, idNodes[2]);
6313                         pts[2] = idNodes[2];
6314                 }
6315                 vtkUnstructuredGrid *ugrid =
6316                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6317                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6318                 newugrid->SetPoints(ugrid->GetPoints());
6319                 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
6320
6321                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6322                 Mapper->SetInput(newugrid);
6323                 Mapper->Update();
6324
6325                 vtkActor *tri = vtkActor::New();
6326                 tri->SetMapper(Mapper);
6327                 tri->SetProperty(ac->GetProperty());
6328                 tri->SetBackfaceProperty(ac->GetBackfaceProperty());
6329                 tri->VisibilityOn();
6330                 mySimulationActors->AddItem(tri);
6331                 theRenderer->AddActor(tri);
6332         }
6333
6334         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6335         renWin->Render();
6336 }
6337
6338 //=============================================================================
6339 /*!
6340  *
6341  */
6342 //=============================================================================
6343 void SMESHGUI::DisplaySimulationQuadrangle(SMESH::SMESH_Mesh_ptr aMesh,
6344         const TColStd_MapOfInteger & MapIndex, bool reverse)
6345 {
6346         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6347                 return;
6348
6349         EraseSimulationActors();
6350         mySimulationActors = vtkActorCollection::New();
6351         vtkRenderer *theRenderer =
6352                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6353                 getRightFrame()->getViewFrame())->getRenderer();
6354         Standard_Boolean result;
6355         SMESH_Actor *ac = FindActor(aMesh, result, true);
6356
6357         vtkUnstructuredGrid *ugrid =
6358                 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6359
6360         if (result)
6361         {
6362                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6363                 int i = 0;
6364                 int idNodes[4];
6365                 vtkIdList *Ids = vtkIdList::New();
6366                 for (; ite.More(); ite.Next())
6367                 {
6368                         idNodes[i] = ite.Key();
6369                         i++;
6370                 }
6371
6372                 float *p0 = ugrid->GetPoint(idNodes[0]);
6373                 float *p1 = ugrid->GetPoint(idNodes[1]);
6374                 float *p2 = ugrid->GetPoint(idNodes[2]);
6375                 float *p3 = ugrid->GetPoint(idNodes[3]);
6376
6377                 gp_Pnt P0(p0[0], p0[1], p0[2]);
6378
6379                 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6380                 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6381                 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6382
6383                 gp_Vec Cross1 = V1 ^ V2;
6384                 gp_Vec Cross2 = V2 ^ V3;
6385
6386                 int tmp;
6387                 if (Cross1.Dot(Cross2) < 0)
6388                 {
6389                         V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6390                         V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6391                         Cross1 = V1 ^ V2;
6392                         Cross2 = V2 ^ V3;
6393
6394                         if (Cross1.Dot(Cross2) < 0)
6395                         {
6396                                 tmp = idNodes[2];
6397                                 idNodes[2] = idNodes[3];
6398                                 idNodes[3] = tmp;
6399                         }
6400                         else
6401                         {
6402                                 tmp = idNodes[1];
6403                                 idNodes[1] = idNodes[2];
6404                                 idNodes[2] = tmp;
6405                         }
6406                 }
6407
6408                 if (reverse)
6409                 {
6410                         Ids->InsertId(0, idNodes[3]);
6411                         Ids->InsertId(1, idNodes[2]);
6412                         Ids->InsertId(2, idNodes[1]);
6413                         Ids->InsertId(3, idNodes[0]);
6414                 }
6415                 else
6416                 {
6417                         Ids->InsertId(0, idNodes[0]);
6418                         Ids->InsertId(1, idNodes[1]);
6419                         Ids->InsertId(2, idNodes[2]);
6420                         Ids->InsertId(3, idNodes[3]);
6421                 }
6422
6423                 //    vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
6424                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6425                 newugrid->SetPoints(ugrid->GetPoints());
6426                 newugrid->InsertNextCell(VTK_QUAD, Ids);
6427
6428                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6429                 Mapper->SetInput(newugrid);
6430                 Mapper->Update();
6431
6432                 vtkActor *quad = vtkActor::New();
6433                 quad->SetMapper(Mapper);
6434                 quad->SetProperty(ac->GetProperty());
6435                 quad->SetBackfaceProperty(ac->GetBackfaceProperty());
6436                 quad->VisibilityOn();
6437                 mySimulationActors->AddItem(quad);
6438                 theRenderer->AddActor(quad);
6439         }
6440         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6441         renWin->Render();
6442 }
6443
6444 //=============================================================================
6445 /*!
6446  *
6447  */
6448 //=============================================================================
6449 void SMESHGUI::DisplaySimulationTetra(SMESH::SMESH_Mesh_ptr aMesh,
6450         const TColStd_MapOfInteger & MapIndex)
6451 {
6452         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6453                 return;
6454
6455         EraseSimulationActors();
6456         mySimulationActors = vtkActorCollection::New();
6457         vtkRenderer *theRenderer =
6458                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6459                 getRightFrame()->getViewFrame())->getRenderer();
6460         Standard_Boolean result;
6461         SMESH_Actor *ac = FindActor(aMesh, result, true);
6462         if (result)
6463         {
6464                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6465                 int i = 0;
6466                 int idNodes[4];
6467                 vtkIdList *Ids = vtkIdList::New();
6468                 for (; ite.More(); ite.Next())
6469                 {
6470                         idNodes[i] = ite.Key();
6471                         i++;
6472                 }
6473
6474                 Ids->InsertId(0, idNodes[0]);
6475                 Ids->InsertId(1, idNodes[1]);
6476                 Ids->InsertId(2, idNodes[2]);
6477                 Ids->InsertId(3, idNodes[3]);
6478
6479                 vtkUnstructuredGrid *ugrid =
6480                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6481                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6482                 newugrid->SetPoints(ugrid->GetPoints());
6483                 newugrid->InsertNextCell(VTK_TETRA, Ids);
6484
6485                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6486                 Mapper->SetInput(newugrid);
6487                 Mapper->Update();
6488
6489                 vtkActor *tetra = vtkActor::New();
6490                 tetra->SetMapper(Mapper);
6491                 tetra->SetProperty(ac->GetProperty());
6492                 tetra->SetBackfaceProperty(ac->GetBackfaceProperty());
6493                 tetra->VisibilityOn();
6494                 mySimulationActors->AddItem(tetra);
6495                 theRenderer->AddActor(tetra);
6496         }
6497         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6498         renWin->Render();
6499 }
6500
6501 //=============================================================================
6502 /*!
6503  *
6504  */
6505 //=============================================================================
6506 void SMESHGUI::DisplaySimulationHexa(SMESH::SMESH_Mesh_ptr aMesh,
6507         const TColStd_MapOfInteger & MapIndex)
6508 {
6509         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6510                 return;
6511
6512         EraseSimulationActors();
6513         mySimulationActors = vtkActorCollection::New();
6514         vtkRenderer *theRenderer =
6515                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6516                 getRightFrame()->getViewFrame())->getRenderer();
6517         Standard_Boolean result;
6518         SMESH_Actor *ac = FindActor(aMesh, result, true);
6519         if (result)
6520         {
6521                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6522                 int i = 0;
6523                 int idNodes[8];
6524                 vtkIdList *Ids = vtkIdList::New();
6525                 for (; ite.More(); ite.Next())
6526                 {
6527                         idNodes[i] = ite.Key();
6528                         i++;
6529                 }
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                 Ids->InsertId(4, idNodes[4]);
6536                 Ids->InsertId(5, idNodes[5]);
6537                 Ids->InsertId(6, idNodes[6]);
6538                 Ids->InsertId(7, idNodes[7]);
6539
6540                 vtkUnstructuredGrid *ugrid =
6541                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6542                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6543                 newugrid->SetPoints(ugrid->GetPoints());
6544                 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
6545
6546                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6547                 Mapper->SetInput(newugrid);
6548                 Mapper->Update();
6549
6550                 vtkActor *hexa = vtkActor::New();
6551                 hexa->SetMapper(Mapper);
6552                 hexa->SetProperty(ac->GetProperty());
6553                 hexa->SetBackfaceProperty(ac->GetBackfaceProperty());
6554                 hexa->VisibilityOn();
6555                 mySimulationActors->AddItem(hexa);
6556                 theRenderer->AddActor(hexa);
6557         }
6558         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6559         renWin->Render();
6560 }
6561
6562 //=============================================================================
6563 /*!
6564  *
6565  */
6566 //=============================================================================
6567 void SMESHGUI::AddFace(SMESH::SMESH_Mesh_ptr aMesh,
6568         const TColStd_MapOfInteger & MapIndex, bool reverse)
6569 {
6570         QApplication::setOverrideCursor(Qt::waitCursor);
6571         Standard_Boolean result;
6572         SMESH_Actor *ac = FindActor(aMesh, result, true);
6573         if (result)
6574         {
6575                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6576                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6577                 anArrayOfIdeces->length(MapIndex.Extent());
6578
6579                 int i = 0;
6580                 for (; ite.More(); ite.Next())
6581                 {
6582                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6583                         i++;
6584                 }
6585
6586                 int tmp;
6587                 if (MapIndex.Extent() == 4)
6588                 {
6589                         int idNodes[4];
6590                         int i = 0;
6591                         TColStd_MapIteratorOfMapOfInteger ite1(MapIndex);
6592                         for (; ite1.More(); ite1.Next())
6593                         {
6594                                 idNodes[i] = ite1.Key();
6595                                 i++;
6596                         }
6597
6598                         vtkUnstructuredGrid *ugrid =
6599                                 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6600                         float *p0 = ugrid->GetPoint(idNodes[0]);
6601                         float *p1 = ugrid->GetPoint(idNodes[1]);
6602                         float *p2 = ugrid->GetPoint(idNodes[2]);
6603                         float *p3 = ugrid->GetPoint(idNodes[3]);
6604
6605                         gp_Pnt P0(p0[0], p0[1], p0[2]);
6606
6607                         gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6608                         gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6609                         gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6610
6611                         gp_Vec Cross1 = V1 ^ V2;
6612                         gp_Vec Cross2 = V2 ^ V3;
6613
6614                         if (Cross1.Dot(Cross2) < 0)
6615                         {
6616
6617                                 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6618                                 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6619                                 Cross1 = V1 ^ V2;
6620                                 Cross2 = V2 ^ V3;
6621
6622                                 if (Cross1.Dot(Cross2) < 0)
6623                                 {
6624                                         tmp = anArrayOfIdeces[2];
6625                                         anArrayOfIdeces[2] = anArrayOfIdeces[3];
6626                                         anArrayOfIdeces[3] = tmp;
6627                                 }
6628                                 else
6629                                 {
6630                                         tmp = anArrayOfIdeces[1];
6631                                         anArrayOfIdeces[1] = anArrayOfIdeces[2];
6632                                         anArrayOfIdeces[2] = tmp;
6633                                 }
6634                         }
6635                 }
6636
6637                 //    int tmp;
6638                 if (reverse)
6639                 {
6640                         for (i = 0; i < (MapIndex.Extent() / 2); i++)
6641                         {
6642                                 tmp = anArrayOfIdeces[i];
6643                                 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent() - i - 1];
6644                                 anArrayOfIdeces[MapIndex.Extent() - i - 1] = tmp;
6645                         }
6646                 }
6647                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6648                 aMeshEditor->AddFace(anArrayOfIdeces);
6649         }
6650         if (myAutomaticUpdate)
6651         {
6652                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6653                 if (Mesh != NULL)
6654                 {
6655                         smeshGUI->DisplayActor(Mesh);
6656                         smeshGUI->DisplayEdges(Mesh);
6657                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6658                         AddActorInSelection(Mesh);
6659                 }
6660         }
6661         QApplication::restoreOverrideCursor();
6662 }
6663
6664 //=============================================================================
6665 /*!
6666  *
6667  */
6668 //=============================================================================
6669 void SMESHGUI::AddVolume(SMESH::SMESH_Mesh_ptr aMesh,
6670         const TColStd_MapOfInteger & MapIndex)
6671 {
6672         QApplication::setOverrideCursor(Qt::waitCursor);
6673         Standard_Boolean result;
6674         SMESH_Actor *ac = FindActor(aMesh, result, true);
6675         if (result)
6676         {
6677                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6678                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6679                 anArrayOfIdeces->length(MapIndex.Extent());
6680
6681                 int i = 0;
6682                 for (; ite.More(); ite.Next())
6683                 {
6684                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6685                         i++;
6686                 }
6687
6688                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6689                 aMeshEditor->AddVolume(anArrayOfIdeces);
6690         }
6691         if (myAutomaticUpdate)
6692         {
6693                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6694                 if (Mesh != NULL)
6695                 {
6696                         smeshGUI->DisplayActor(Mesh);
6697                         smeshGUI->DisplayEdges(Mesh);
6698                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6699                         AddActorInSelection(Mesh);
6700                 }
6701         }
6702         QApplication::restoreOverrideCursor();
6703 }
6704
6705 //=============================================================================
6706 /*!
6707  *
6708  */
6709 //=============================================================================
6710 void SMESHGUI::AddEdge(SMESH::SMESH_Mesh_ptr aMesh,
6711         const TColStd_MapOfInteger & MapIndex)
6712 {
6713         QApplication::setOverrideCursor(Qt::waitCursor);
6714         Standard_Boolean result;
6715         SMESH_Actor *ac = FindActor(aMesh, result, true);
6716         if (result)
6717         {
6718                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6719                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6720                 anArrayOfIdeces->length(MapIndex.Extent());
6721
6722                 int i = 0;
6723                 for (; ite.More(); ite.Next())
6724                 {
6725                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6726                         i++;
6727                 }
6728
6729                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6730                 aMeshEditor->AddEdge(anArrayOfIdeces);
6731         }
6732         if (myAutomaticUpdate)
6733         {
6734                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6735                 if (Mesh != NULL)
6736                 {
6737                         smeshGUI->DisplayActor(Mesh);
6738                         smeshGUI->DisplayEdges(Mesh);
6739                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6740                         AddActorInSelection(Mesh);
6741                 }
6742         }
6743         QApplication::restoreOverrideCursor();
6744 }
6745
6746 //=============================================================================
6747 /*!
6748  *
6749  */
6750 //=============================================================================
6751 void SMESHGUI::AddNode(SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
6752 {
6753         QApplication::setOverrideCursor(Qt::waitCursor);
6754         Standard_Boolean result;
6755         SMESH_Actor *ac = FindActor(aMesh, result, true);
6756         if (result)
6757         {
6758                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6759                 aMeshEditor->AddNode(x, y, z);
6760
6761                 if (myAutomaticUpdate)
6762                 {
6763                         SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6764                         if (Mesh != NULL)
6765                         {
6766                                 smeshGUI->DisplayActor(Mesh);
6767                                 smeshGUI->DisplayEdges(Mesh);
6768                                 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6769                                 AddActorInSelection(Mesh);
6770                         }
6771                 }
6772         }
6773         QApplication::restoreOverrideCursor();
6774 }
6775
6776 //=============================================================================
6777 /*!
6778  *
6779  */
6780 //=============================================================================
6781 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor * ac)
6782 {
6783         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6784                 return;
6785
6786         EraseSimulationActors();
6787         mySimulationActors2D = vtkActor2DCollection::New();
6788
6789         vtkRenderer *theRenderer =
6790                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6791                 getRightFrame()->getViewFrame())->getRenderer();
6792
6793         vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
6794         gs2->SetGlyphTypeToTriangle();
6795         gs2->FilledOff();
6796
6797         vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
6798         legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
6799         legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.);       //relative to Position
6800
6801         legend->SetNumberOfEntries(4);
6802         legend->SetEntryString(0, tr("SMESH_BOUNDARYEDGES"));
6803         legend->SetEntrySymbol(0, gs2->GetOutput());
6804         legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.));
6805         legend->SetEntryString(1, tr("SMESH_MANIFOLDEDGES"));
6806         legend->SetEntrySymbol(1, gs2->GetOutput());
6807         legend->SetEntryColor(1,
6808                 ac->GetMapper()->GetLookupTable()->GetColor(0.666667));
6809         legend->SetEntryString(2, tr("SMESH_NONMANIFOLDEDGES"));
6810         legend->SetEntrySymbol(2, gs2->GetOutput());
6811         legend->SetEntryColor(2,
6812                 ac->GetMapper()->GetLookupTable()->GetColor(0.222222));
6813         legend->SetEntryString(3, tr("SMESH_FEATUREEDGES"));
6814         legend->SetEntrySymbol(3, gs2->GetOutput());
6815         legend->SetEntryColor(3,
6816                 ac->GetMapper()->GetLookupTable()->GetColor(0.444444));
6817         legend->SetPadding(5);
6818         //  legend->GetProperty()->SetColor();
6819
6820         mySimulationActors2D->AddItem(legend);
6821         theRenderer->AddActor2D(legend);
6822
6823         // Update the view
6824         myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->
6825                 Repaint();
6826 }
6827
6828 //===============================================================================
6829 // function : OnEditDelete()
6830 // purpose  :
6831 //===============================================================================
6832 void SMESHGUI::OnEditDelete()
6833 {
6834         if (QAD_MessageBox::warn2
6835                 (QAD_Application::getDesktop(),
6836                         tr("SMESH_WRN_WARNING"),
6837                         tr("SMESH_REALLY_DELETE"),
6838                         tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
6839                 return;
6840
6841         int nbSf = myActiveStudy->getStudyFramesCount();
6842
6843         Standard_Boolean found;
6844         SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
6845         SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
6846         SALOMEDS::GenericAttribute_var anAttr;
6847         SALOMEDS::AttributeIOR_var anIOR;
6848
6849         SALOME_Selection *Sel =
6850                 SALOME_Selection::Selection(myActiveStudy->getSelection());
6851         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
6852         for (; It.More(); It.Next())
6853         {
6854                 Handle(SALOME_InteractiveObject) IObject = It.Value();
6855                 if (IObject->hasEntry())
6856                 {
6857                         SALOMEDS::SObject_var SO =
6858                                 myStudy->FindObjectID(IObject->getEntry());
6859
6860                         /* Erase child graphical objects */
6861                         SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
6862                         for (; it->More(); it->Next())
6863                         {
6864                                 SALOMEDS::SObject_var CSO = it->Value();
6865                                 if (CSO->FindAttribute(anAttr, "AttributeIOR"))
6866                                 {
6867                                         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6868
6869                                         for (int i = 0; i < nbSf; i++)
6870                                         {
6871                                                 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
6872                                                 if (sf->getTypeView() == VIEW_VTK)
6873                                                 {
6874                                                         vtkRenderer *Renderer =
6875                                                                 ((VTKViewer_ViewFrame *) smeshGUI->
6876                                                                 myActiveStudy->getActiveStudyFrame()->
6877                                                                 getRightFrame()->getViewFrame())->getRenderer();
6878                                                         SMESH_Actor *ac =
6879                                                                 smeshGUI->FindActorByEntry(CSO->GetID(), found,
6880                                                                 false);
6881                                                         if (found)
6882                                                         {
6883                                                                 Renderer->RemoveActor(ac->EdgeDevice);
6884                                                                 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6885                                                                 Renderer->RemoveActor(ac);
6886                                                         }
6887                                                 }
6888                                         }
6889                                 }
6890                         }
6891
6892                         /* Erase main graphical object */
6893                         for (int i = 0; i < nbSf; i++)
6894                         {
6895                                 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
6896                                 if (sf->getTypeView() == VIEW_VTK)
6897                                 {
6898                                         vtkRenderer *Renderer =
6899                                                 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
6900                                                 getActiveStudyFrame()->getRightFrame()->
6901                                                 getViewFrame())->getRenderer();
6902                                         VTKViewer_RenderWindowInteractor *myRenderInter =
6903                                                 ((VTKViewer_ViewFrame *) sf->getRightFrame()->
6904                                                 getViewFrame())->getRWInteractor();
6905                                         SMESH_Actor *ac =
6906                                                 smeshGUI->FindActorByEntry(IObject->getEntry(), found,
6907                                                 false);
6908                                         if (found)
6909                                         {
6910                                                 Renderer->RemoveActor(ac->EdgeDevice);
6911                                                 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6912                                         }
6913                                         myRenderInter->Remove(IObject);
6914                                 }
6915                         }
6916
6917                         /* Erase objects in Study */
6918                         SALOMEDS::SObject_var obj =
6919                                 myStudy->FindObjectID(IObject->getEntry());
6920                         if (!obj->_is_nil())
6921                         {
6922                                 QAD_Operation *op =
6923                                         new SALOMEGUI_ImportOperation(myActiveStudy);
6924                                 op->start();
6925                                 aStudyBuilder->RemoveObject(obj);
6926                                 op->finish();
6927                         }
6928
6929                 }                                               /* IObject->hasEntry() */
6930         }                                                       /* more/next           */
6931
6932         /* Clear any previous selection */
6933         Sel->ClearIObjects();
6934         myActiveStudy->updateObjBrowser();
6935 }