Salome HOME
Add a MEDFILE attribut for selection in Efficas. Patch submited by P. Rascle on 2004...
[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                         QString filename;
3496                         if (theCommandID == 122)
3497                         {                                       // EXPORT MED
3498                                 QString filename = QAD_FileDlg::getFileName(parent,
3499                                         "",
3500                                         tr("MED files (*.med)"),
3501                                         tr("Export mesh"),
3502                                         false);
3503                                 if (!filename.isEmpty())
3504                                 {
3505                                         QApplication::setOverrideCursor(Qt::waitCursor);
3506                                         aMesh->Export(filename.latin1(), "MED");
3507                                         QApplication::restoreOverrideCursor();
3508                                 }
3509                         }
3510                         else if (theCommandID == 121)
3511                         {                                       // EXPORT DAT
3512                                 QString filename = QAD_FileDlg::getFileName(parent,
3513                                         "",
3514                                         tr("DAT files (*.dat)"),
3515                                         tr("Export mesh"),
3516                                         false);
3517                                 if (!filename.isEmpty())
3518                                 {
3519                                         QApplication::setOverrideCursor(Qt::waitCursor);
3520                                         aMesh->Export(filename.latin1(), "DAT");
3521                                         QApplication::restoreOverrideCursor();
3522                                 }
3523                         }
3524                         else if (theCommandID == 123)
3525                         {                                       // EXPORT UNV
3526                                 QString filename = QAD_FileDlg::getFileName(parent,
3527                                         "",
3528                                         tr("IDEAS files (*.unv)"),
3529                                         tr("Export mesh"),
3530                                         false);
3531                                 if (!filename.isEmpty())
3532                                 {
3533                                         QApplication::setOverrideCursor(Qt::waitCursor);
3534                                         aMesh->Export(filename.latin1(), "UNV");
3535                                         QApplication::restoreOverrideCursor();
3536                                 }
3537                         }
3538                         else
3539                                 aMesh->Export(filename.latin1(), "DAT");
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
3549                                 SALOMEDS::StudyBuilder_var aStudyBuilder =
3550                                         smeshGUI->myStudy->NewBuilder();
3551
3552                                 anAttr =
3553                                         aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
3554                                 aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
3555                                 aFileName->SetValue(filename.latin1());
3556
3557                                 // Add a MEDFILE attribute to make selection in Efficas
3558                                 if (theCommandID == 122)
3559                                 { // EXPORT MED
3560                                         QString medfilename="FICHIERMED"+filename;
3561                                         anAttr = aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
3562                                         SALOMEDS::AttributeComment_var MEDFileName;
3563                                         MEDFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
3564                                         MEDFileName->SetValue(medfilename.latin1());
3565                                 } // EXPORT MED
3566                         }
3567
3568                         QApplication::restoreOverrideCursor();
3569                 }
3570         }
3571 }
3572
3573 //=============================================================================
3574 /*!
3575  *
3576  */
3577 //=============================================================================
3578 void SMESHGUI::Import_Document(QAD_Desktop * parent, int theCommandID)
3579 {
3580         QString filter;
3581         string myExtension;
3582
3583         if (theCommandID == 113)
3584         {
3585                 filter = tr("MED files (*.med)");
3586                 myExtension = string("MED");
3587         }
3588         else if (theCommandID == 112)
3589         {
3590                 filter = tr("IDEAS files (*.unv)");
3591                 myExtension = string("UNV");
3592         }
3593         else if (theCommandID == 111)
3594         {
3595                 filter = tr("DAT files (*.dat)");
3596                 myExtension = string("DAT");
3597         }
3598
3599         QString filename = QAD_FileDlg::getFileName(parent, "", filter,
3600                 tr("Import document"), true);
3601
3602         if (!filename.isEmpty())
3603         {
3604                 QApplication::setOverrideCursor(Qt::waitCursor);
3605                 try
3606                 {
3607                         if (!myComponentMesh->_is_nil())
3608                         {
3609                                 SMESH::SMESH_Mesh_var aMesh =
3610                                         myComponentMesh->Import(myStudyId, filename.latin1(),
3611                                         myExtension.c_str());
3612         
3613                                 if (!aMesh->_is_nil())
3614                                 {
3615                                         SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh(aMesh);
3616                                         myStudyAPI.SetName(SM, filename);
3617                                 }
3618                         }
3619                 }
3620                 catch(const SALOME::SALOME_Exception & S_ex)
3621                 {
3622                         QtCatchCorbaException(S_ex);
3623                 }
3624                 myActiveStudy->updateObjBrowser(true);
3625                 QApplication::restoreOverrideCursor();
3626         }
3627 }
3628
3629 //=============================================================================
3630 /*!
3631  *
3632  */
3633 //=============================================================================
3634 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3635         QAD_StudyFrame * studyFrame)
3636 {
3637         SMESHGUI::GetOrCreateSMESHGUI(parent);
3638         return false;
3639 }
3640
3641 //=============================================================================
3642 /*!
3643  *
3644  */
3645 //=============================================================================
3646 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3647         QAD_StudyFrame * studyFrame)
3648 {
3649         SMESHGUI::GetOrCreateSMESHGUI(parent);
3650
3651         return true;
3652 }
3653
3654 //=============================================================================
3655 /*!
3656  *
3657  */
3658 //=============================================================================
3659 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3660         QAD_StudyFrame * studyFrame)
3661 {
3662         SMESHGUI::GetOrCreateSMESHGUI(parent);
3663
3664         return true;
3665 }
3666
3667 //=============================================================================
3668 /*!
3669  *
3670  */
3671 //=============================================================================
3672 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
3673 {
3674         SMESHGUI::GetOrCreateSMESHGUI(parent);
3675
3676         /* Display mode */
3677         QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3678         if (DisplayMode.compare("") == 0)
3679         {
3680                 DisplayMode = "Shading";
3681                 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3682         }
3683
3684         if (DisplayMode.compare("Wireframe") == 0)
3685         {
3686                 parent->menuBar()->setItemChecked(10003, false);
3687                 parent->menuBar()->setItemChecked(10002, false);
3688                 parent->menuBar()->setItemChecked(10001, true);
3689         }
3690         else if (DisplayMode.compare("Shading") == 0)
3691         {
3692                 parent->menuBar()->setItemChecked(10003, false);
3693                 parent->menuBar()->setItemChecked(10002, true);
3694                 parent->menuBar()->setItemChecked(10001, false);
3695         }
3696         else if (DisplayMode.compare("Shrink") == 0)
3697         {
3698                 parent->menuBar()->setItemChecked(10003, true);
3699                 parent->menuBar()->setItemChecked(10002, false);
3700                 parent->menuBar()->setItemChecked(10001, false);
3701         }
3702
3703         /* Automatic Update */
3704         QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3705         if (AutoUpdate.compare("true") == 0)
3706         {
3707                 parent->menuBar()->setItemChecked(1001, true);
3708                 smeshGUI->myAutomaticUpdate = true;
3709         }
3710         else
3711         {
3712                 parent->menuBar()->setItemChecked(1001, false);
3713                 smeshGUI->myAutomaticUpdate = false;
3714         }
3715
3716         return true;
3717 }
3718
3719 //=============================================================================
3720 /*!
3721  *
3722  */
3723 //=============================================================================
3724 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent,
3725         QString & theObject)
3726 {
3727         /* Create or retrieve an object SMESHGUI */
3728         SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3729
3730         // NRI : Temporary added
3731         //  if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3732         //    theObject = "NothingSelected";
3733         //    theContext = "NothingSelected";
3734         //  }
3735         // NRI
3736
3737         SALOME_Selection *Sel =
3738                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3739         int nbSel = Sel->IObjectCount();
3740         if (nbSel == 0)
3741         {
3742                 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3743                         VIEW_VTK)
3744                 {
3745                         vtkScalarBarActor *aScalarBar = smeshGUI->GetScalarBar();
3746                         if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1))
3747                         {
3748                                 theObject = "ScalarBar";
3749                                 theContext = "";
3750                         }
3751                         else
3752                         {
3753                                 theObject = "NothingSelected";
3754                                 theContext = "NothingSelected";
3755                         }
3756                 }
3757                 else
3758                 {
3759                         theObject = "NothingSelected";
3760                         theContext = "NothingSelected";
3761                 }
3762         }
3763         else if (nbSel == 1)
3764         {
3765                 theObject = smeshGUI->CheckTypeObject(Sel->firstIObject());
3766                 theContext = "";
3767         }
3768         else
3769         {
3770                 theObject = smeshGUI->CheckHomogeneousSelection();
3771                 theContext = "";
3772         }
3773 }
3774
3775 //=============================================================================
3776 /*!
3777  *
3778  */
3779 //=============================================================================
3780 bool SMESHGUI::CustomPopup(QAD_Desktop * parent,
3781         QPopupMenu * popup,
3782         const QString & theContext,
3783         const QString & theParent, const QString & theObject)
3784 {
3785         // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3786         //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3787         //  return false;
3788         /* Create or retrieve an object SMESHGUI */
3789         SMESHGUI::GetOrCreateSMESHGUI(parent);
3790
3791         // NRI : Temporary added
3792         //  if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3793         //    return false;
3794         //  }
3795         // NRI
3796
3797         SALOME_Selection *Sel =
3798                 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3799         QAD_StudyFrame *studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3800         int nbSel = Sel->IObjectCount();
3801
3802         if (nbSel == 0)
3803         {
3804                 if (studyFrame->getTypeView() != VIEW_VTK)
3805                         popup->clear();
3806                 return false;
3807         }
3808         else if (nbSel == 1)
3809         {
3810                 QString parentComp =
3811                         ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
3812                 // First check type of active viewer (VTK required)
3813                 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
3814                         parent->getActiveComponent())
3815                 {
3816                         //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3817                         while (1)
3818                         {
3819                                 int id = popup->idAt(0);
3820                                 if (id <= QAD_TopLabel_Popup_ID)
3821                                         popup->removeItemAt(0);
3822                                 else
3823                                         break;
3824                         }
3825                         if (theObject.compare("Component") == 0)
3826                         {
3827                                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3828                         }
3829                         return false;
3830                 }
3831
3832                 // Remove common popup items for Submesh, Hypothesis and Algorithm
3833                 if (theObject.compare("SubMesh") == 0 ||
3834                         theObject.compare("Hypothesis") == 0 ||
3835                         theObject.compare("Algorithm") == 0)
3836                 {
3837                         popup->removeItem(QAD_Display_Popup_ID);
3838                         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3839                         popup->removeItem(QAD_Erase_Popup_ID);
3840                         int id = popup->idAt(popup->count() - 1);       // last item
3841                         if (id < 0 && id != -1)
3842                                 popup->removeItem(id);  // separator
3843                 }
3844
3845                 if (theObject.compare("Component") == 0)
3846                 {
3847                         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3848                         return true;
3849                 }
3850
3851                 int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
3852                 QFont f = QApplication::font();
3853                 f.setBold(TRUE);
3854
3855                 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3856
3857                 if (theParent.compare("Viewer") == 0)
3858                 {
3859                         if (popup->idAt(0) == id)
3860                         {
3861                                 popup->removeItem(id);
3862                                 popup->insertItem(new CustomItem(QString(IObject->getName()),
3863                                                 f), id, 0);
3864                         }
3865
3866                         Standard_Boolean res;
3867                         SMESH_Actor *ac =
3868                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3869                         if (res && studyFrame->getTypeView() == VIEW_VTK)
3870                         {
3871                                 VTKViewer_RenderWindowInteractor *myRenderInter =
3872                                         ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
3873                                         getViewFrame())->getRWInteractor();
3874                                 if (myRenderInter->isVisible(IObject))
3875                                 {
3876                                         popup->removeItem(QAD_Display_Popup_ID);
3877                                 }
3878                                 else
3879                                 {
3880                                         popup->removeItem(QAD_Erase_Popup_ID);
3881                                 }
3882                         }
3883                         else
3884                         {
3885                                 popup->removeItem(QAD_Erase_Popup_ID);
3886                                 if (!res)
3887                                 {                               // mesh not computed -> can't display it
3888                                         popup->removeItem(QAD_Display_Popup_ID);
3889                                         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3890                                         popup->removeItemAt(popup->count() - 1);        //separator
3891                                 }
3892                         }
3893                 }
3894                 else if (theParent.compare("ObjectBrowser") == 0)
3895                 {
3896                         if (theObject.compare("Mesh") == 0 ||
3897                                 theObject.compare("SubMesh") == 0 ||
3898                                 theObject.compare("Hypothesis") == 0 ||
3899                                 theObject.compare("Algorithm") == 0)
3900                         {
3901                                 popup->removeItemAt(0);
3902                         }
3903                         else
3904                         {
3905                                 if (popup->idAt(0) == id)
3906                                 {
3907                                         popup->removeItem(id);
3908                                         popup->removeItemAt(0); //separator
3909                                 }
3910                         }
3911
3912                         Standard_Boolean res;
3913                         SMESH_Actor *ac =
3914                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3915                         if (res && studyFrame->getTypeView() == VIEW_VTK)
3916                         {
3917                                 VTKViewer_RenderWindowInteractor *myRenderInter =
3918                                         ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
3919                                         getViewFrame())->getRWInteractor();
3920                                 if (myRenderInter->isVisible(IObject))
3921                                 {
3922                                         popup->removeItem(QAD_Display_Popup_ID);
3923                                 }
3924                                 else
3925                                 {
3926                                         popup->removeItem(QAD_Erase_Popup_ID);
3927                                 }
3928                         }
3929                         else
3930                         {
3931                                 if (theObject.compare("Mesh") == 0 ||
3932                                         theObject.compare("SubMesh") == 0 ||
3933                                         theObject.compare("Hypothesis") == 0 ||
3934                                         theObject.compare("Algorithm") == 0)
3935                                 {
3936                                 }
3937                                 else
3938                                 {
3939                                         popup->removeItem(QAD_Erase_Popup_ID);
3940                                         if (!res)
3941                                         {                       // mesh not computed -> can't display it
3942                                                 popup->removeItem(QAD_Display_Popup_ID);
3943                                                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3944                                                 popup->removeItemAt(popup->count() - 1);        //separator
3945                                         }
3946                                 }
3947                         }
3948                 }
3949         }
3950         else
3951         {
3952                 QString parentComp =
3953                         ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
3954                 QAD_StudyFrame *studyFrame =
3955                         smeshGUI->myActiveStudy->getActiveStudyFrame();
3956                 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
3957                         parent->getActiveComponent())
3958                 {
3959                         //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3960                         while (1)
3961                         {
3962                                 int id = popup->idAt(0);
3963                                 if (id <= QAD_TopLabel_Popup_ID && id != -1)
3964                                         popup->removeItemAt(0);
3965                                 else
3966                                         break;
3967                         }
3968                         if (parentComp.isNull())
3969                         {                                       // objects from several components are selected
3970                                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3971                                 popup->removeItem(QAD_Display_Popup_ID);
3972                                 popup->removeItem(QAD_Erase_Popup_ID);
3973                                 int id = popup->idAt(popup->count() - 1);       // last item
3974                                 if (id < 0 && id != -1)
3975                                         popup->removeItem(id);  // separator
3976                         }
3977                         return false;
3978                 }
3979
3980                 QString type = smeshGUI->CheckHomogeneousSelection();
3981                 if (type.compare("Heterogeneous Selection") != 0)
3982                 {
3983                         int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
3984                         QFont f = QApplication::font();
3985                         f.setBold(TRUE);
3986                         popup->removeItem(id);
3987                         popup->insertItem(new CustomItem(QString("%1 ").arg(nbSel) + type +
3988                                         " (s) ", f), id, 0);
3989                 }
3990         }
3991         return false;
3992 }
3993
3994 /**
3995  * Ensures that the actor for the given <theIO> exists in the active VTK view
3996  * @TODO Handle multiple selection.
3997  */
3998 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
3999 {
4000         MESSAGE("SMESHGUI::BuildPresentation("<<theIO->getEntry()<<")");
4001         /* Create or retrieve an object SMESHGUI */
4002         SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
4003
4004         QAD_StudyFrame *activeFrame =
4005                 smeshGUI->myActiveStudy->getActiveStudyFrame();
4006         if (activeFrame->getTypeView() == VIEW_VTK)
4007         {
4008                 // VTK
4009                 // Some ideas to handle multiple selection...
4010                 /*SALOMEDS::SObject_var fatherSF =
4011                         smeshGUI->myStudy->FindObjectID(activeFrame->entry());
4012
4013                 SALOME_Selection *Sel =
4014                         SALOME_Selection::Selection(smeshGUI->myActiveStudy->
4015                         getSelection());
4016                 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4017
4018             for(;It.More();It.Next()) {
4019       Handle(SALOME_InteractiveObject) IObject = It.Value();*/
4020                 Handle(SALOME_InteractiveObject) IObject = theIO;
4021                 if (IObject->hasEntry())
4022                 {
4023                         // Look for the actor in all views
4024                         Standard_Boolean res;
4025                         SMESH_Actor *ac =
4026                                 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
4027                         
4028                         if (!res)
4029                         {
4030                                 SALOMEDS::SObject_var aMorSM=smeshGUI->myStudy->FindObjectID( IObject->getEntry());
4031                                 SALOMEDS::GenericAttribute_var anAttr;
4032                                 SALOMEDS::AttributeIOR_var     anIOR;
4033                                 if(aMorSM->FindAttribute(anAttr, "AttributeIOR"))
4034                                 {
4035                                         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4036                                         SMESH::SMESH_Mesh_var aM =
4037                                                 SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()));
4038                                         if(!aM->_is_nil())
4039                                         {
4040                                                 smeshGUI->InitActor(aM);
4041                                                 ac = smeshGUI->ReadScript(aM);
4042                                                 smeshGUI->DisplayActor( ac, true );
4043                                                 smeshGUI->DisplayEdges( ac );
4044                                                 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
4045                                         }
4046                                         else
4047                                         {
4048                                                 MESSAGE("Do not know how to display something which is not a SMESH_Mesh");
4049                                         }
4050                                 }
4051                                 else
4052                                 {
4053                                         MESSAGE("The object "<<theIO->getEntry()<<
4054                                                 " do not have \"AttributeIOR\" attribute");
4055                                 }
4056                         }
4057                         else
4058                         {
4059                                 // The actor exists in some view
4060                                 // Check whether the actor belongs to the active view
4061                                 VTKViewer_RenderWindowInteractor *rwInter =
4062                                         ((VTKViewer_ViewFrame *) activeFrame->getRightFrame()->
4063                                         getViewFrame())->getRWInteractor();
4064
4065                                 // The actor belongs to inactive view -> create a copy and display it in the active view
4066                                 if (!rwInter->isInViewer(IObject))
4067                                 {
4068                                         if(ac->GetMapper()==NULL)
4069                                         {
4070                                                 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(theIO, res);
4071                                                 ac=smeshGUI->ReadScript(aMesh);
4072                                         }
4073                                         SMESH_Actor *acCopy = SMESH_Actor::New();
4074                                         acCopy->ShallowCopy(ac);
4075                                         ac = acCopy;
4076                                 }
4077                                 smeshGUI->DisplayActor(ac, false);
4078                                 smeshGUI->DisplayEdges(ac);
4079                                 smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
4080                         }
4081                 }
4082         }
4083         else
4084         {
4085                 MESSAGE("BuildPresentation() must not be called while non-VTK view is active");
4086         }
4087 }
4088
4089 //=============================================================================
4090 /*!
4091  *
4092  */
4093 //=============================================================================
4094 void SMESHGUI::setOrb()
4095 {
4096         try
4097         {
4098                 ORB_INIT & init = *SINGLETON_ < ORB_INIT >::Instance();
4099                 ASSERT(SINGLETON_ < ORB_INIT >::IsAlreadyExisting());
4100                 _orb = init(0, 0);
4101         } catch(...)
4102         {
4103                 INFOS("internal error : orb not found");
4104                 _orb = 0;
4105         }
4106         ASSERT(!CORBA::is_nil(_orb));
4107 }
4108
4109 /**
4110  * Get the history of all commands made in the SMESH server. This list of command
4111  * is used to display the mesh in the VTK view
4112  * @TODO Handle the REMOVE_ALL command.
4113  */
4114 SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
4115 {
4116         MESSAGE("SMESHGUI::ReadScript");
4117         SMESH_Actor *MeshActor;
4118         if (!aMesh->_is_nil())
4119         {
4120                 Standard_Boolean result;
4121                 MeshActor = FindActor(aMesh, result, false);
4122                 if (result)
4123                 {
4124                         SMESH::log_array_var aSeq = aMesh->GetLog(true);
4125                         MESSAGE("SMESHGUI::ReadScript: The log contains "<<aSeq->length()
4126                                 <<" commands.");
4127
4128                         for (unsigned int ind = 0; ind < aSeq->length(); ind++)
4129                         {
4130                                 switch (aSeq[ind].commandType)
4131                                 {
4132                                 case SMESH::ADD_NODE:
4133                                 {
4134                                         AddNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4135                                                 aSeq[ind].indexes);
4136                                         break;
4137                                 }
4138                                 case SMESH::ADD_EDGE:
4139                                 {
4140                                         AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
4141                                         break;
4142                                 }
4143                                 case SMESH::ADD_TRIANGLE:
4144                                 {
4145                                         AddTriangles(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4146                                                 aSeq[ind].indexes);
4147                                         break;
4148                                 }
4149                                 case SMESH::ADD_QUADRANGLE:
4150                                 {
4151                                         AddQuadrangles(MeshActor, aSeq[ind].number,
4152                                                 aSeq[ind].coords, aSeq[ind].indexes);
4153                                         break;
4154                                 }
4155                                 case SMESH::ADD_TETRAHEDRON:
4156                                 {
4157                                         AddTetras(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4158                                                 aSeq[ind].indexes);
4159                                         break;
4160                                 }
4161                                 case SMESH::ADD_PYRAMID:
4162                                 {
4163                                         break;
4164                                 }
4165                                 case SMESH::ADD_PRISM:
4166                                 {
4167                                         break;
4168                                 }
4169                                 case SMESH::ADD_HEXAHEDRON:
4170                                 {
4171                                         AddHexaedres(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4172                                                 aSeq[ind].indexes);
4173                                         break;
4174                                 }
4175                                 case SMESH::REMOVE_NODE:
4176                                 {
4177                                         RemoveNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4178                                                 aSeq[ind].indexes);
4179                                         break;
4180                                 }
4181                                 case SMESH::REMOVE_ELEMENT:
4182                                 {
4183                                         RemoveElements(MeshActor, aSeq[ind].number,
4184                                                 aSeq[ind].coords, aSeq[ind].indexes);
4185                                         break;
4186                                 }
4187                                 case SMESH::REMOVE_ALL:
4188                                         MESSAGE("REMOVE_ALL command not yet implemented");
4189                                         break;
4190                                 default: MESSAGE("Warning: Unknown script command.");
4191                                 }
4192                         }
4193                         return MeshActor;
4194                 }
4195         }
4196         return NULL;
4197 }
4198
4199 //=============================================================================
4200 /*!
4201  *
4202  */
4203 //=============================================================================
4204 void SMESHGUI::Dump(SMESH_Actor * Mactor)
4205 {
4206         vtkUnstructuredGrid *ugrid =
4207                 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
4208         vtkPoints *Pts = ugrid->GetPoints();
4209         int nbPts = Pts->GetNumberOfPoints();
4210         int nbCells = ugrid->GetNumberOfCells();
4211
4212         FILE *In;
4213         int i, j;
4214         In = fopen("/tmp/dumpMesh", "w+");
4215         fprintf(In, "%d %d\n", nbPts, nbCells);
4216         for (int i = 0; i < nbPts; i++)
4217         {
4218                 float *p = ugrid->GetPoint(i);
4219                 fprintf(In, "%d %e %e %e\n", i, p[0], p[1], p[2]);
4220         }
4221
4222         for (int i = 0; i < nbCells; i++)
4223         {
4224                 fprintf(In, "%d %d", i, ugrid->GetCell(i)->GetCellType());
4225                 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
4226                 for (j = 0; j < Id->GetNumberOfIds(); j++)
4227                 {
4228                         fprintf(In, " %d", Id->GetId(j));
4229                 }
4230                 fprintf(In, "\n");
4231         }
4232         fclose(In);
4233 }
4234
4235 //=============================================================================
4236 /*!
4237  *
4238  */
4239 //=============================================================================
4240 void SMESHGUI::AddNodes(SMESH_Actor * Mactor, int number,
4241         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4242 {
4243         //MESSAGE("SMESHGUI::AddNodes(number="<<number<<", indexes.length()="<<indexes.length()<<")");
4244         QApplication::setOverrideCursor(Qt::waitCursor);
4245         if (Mactor->GetMapper() == NULL)
4246         {
4247                 vtkPoints *Pts = vtkPoints::New();
4248                 SMESH_Grid *ugrid = SMESH_Grid::New();
4249                 ugrid->Allocate();
4250
4251                 int i = 1;
4252                 int j = 1;
4253                 while (i <= number)
4254                 {
4255                         int idVTK =
4256                                 Pts->InsertNextPoint(coords[j - 1], coords[j], coords[j + 1]);
4257                         //Mactor->AddNode( indexes[i-1], idVTK );
4258                         ugrid->AddNode(indexes[i - 1], idVTK);
4259                         i++;
4260                         j = j + 3;
4261                 }
4262                 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4263                 ugrid->SetPoints(Pts);
4264                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4265                 PtsMapper->SetInput(ugrid);
4266                 Mactor->DataSource = PtsMapper->GetInput();
4267                 Mactor->SetMapper(PtsMapper);
4268         }
4269         else
4270         {
4271                 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4272                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4273                 int i = 1;
4274                 int j = 1;
4275                 while (i <= number)
4276                 {
4277                         int idVTK =
4278                                 ugrid->GetPoints()->InsertNextPoint(coords[j - 1], coords[j],
4279                                 coords[j + 1]);
4280                         ugrid->AddNode(indexes[i - 1], idVTK);
4281                         i++;
4282                         j = j + 3;
4283                 }
4284                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4285                 PtsMapper->SetInput(ugrid);
4286                 Mactor->DataSource = PtsMapper->GetInput();
4287                 Mactor->SetMapper(PtsMapper);
4288         }
4289         QApplication::restoreOverrideCursor();
4290 }
4291
4292 //=============================================================================
4293 /*!
4294  *
4295  */
4296 //=============================================================================
4297 void SMESHGUI::AddNode(SMESH_Actor * Mactor, int idnode, float x, float y,
4298         float z)
4299 {
4300         QApplication::setOverrideCursor(Qt::waitCursor);
4301         MESSAGE("SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z);
4302         
4303         if (Mactor->GetMapper() == NULL)
4304         {
4305                 vtkPoints *Pts = vtkPoints::New();
4306                 int idVTK = Pts->InsertNextPoint(x, y, z);
4307                 //Mactor->AddNode( idnode, idVTK );
4308                 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4309                 SMESH_Grid *ugrid = SMESH_Grid::New();
4310                 ugrid->Allocate();
4311                 ugrid->AddNode(idnode, idVTK);
4312                 ugrid->SetPoints(Pts);
4313                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4314                 PtsMapper->SetInput(ugrid);
4315                 Mactor->DataSource = PtsMapper->GetInput();
4316                 Mactor->SetMapper(PtsMapper);
4317         }
4318         else
4319         {
4320                 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4321                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4322                 int idVTK = ugrid->GetPoints()->InsertNextPoint(x, y, z);
4323                 //Mactor->AddNode( idnode, idVTK );
4324                 ugrid->AddNode(idnode, idVTK);
4325                 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4326                 PtsMapper->SetInput(ugrid);
4327                 Mactor->DataSource = PtsMapper->GetInput();
4328                 Mactor->SetMapper(PtsMapper);
4329         }
4330         QApplication::restoreOverrideCursor();
4331 }
4332
4333 //=============================================================================
4334 /*!
4335  *
4336  */
4337 //=============================================================================
4338 void SMESHGUI::RemoveNode(SMESH_Actor * Mactor, int idnode)
4339 {
4340         MESSAGE(" OLD RemoveNode method ")
4341 //   int id = Mactor->GetIdVTKNode( idnode );
4342 //    MESSAGE ( " RemoveNode id VTK " << id )
4343 //    if ( Mactor->GetMapper() != NULL ) {
4344 //      vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4345 //      vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4346 //      vtkPoints *Pts = ugrid->GetPoints();
4347 //      vtkPoints *newPts = vtkPoints::New();
4348 //      int nbPts = Pts->GetNumberOfPoints();
4349 //      bool findPt = false;
4350 //      for ( int i = 0; i < nbPts; i++ ) {
4351 //        if ( id != i ) {
4352 //      if ( !findPt)
4353 //        newPts->InsertPoint(i, Pts->GetPoint(i) );
4354 //      else
4355 //        newPts->InsertPoint(i-1, Pts->GetPoint(i) );
4356 //        } else {
4357 //      findPt = true;
4358 //      Mactor->RemoveNode( idnode );
4359 //        }
4360 //      }
4361 //      newUgrid->SetPoints(newPts);
4362 //      int nbCells = ugrid->GetNumberOfCells();
4363 //      for ( int i = 0; i < nbCells; i++ ) {
4364 //        vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4365 //        vtkIdList *newIds = vtkIdList::New();
4366 //        int nbIds = Ids->GetNumberOfIds();
4367 //        newIds->SetNumberOfIds(nbIds);
4368 //        for ( int j = 0; j < nbIds; j++ ) {
4369 //      int theid = Ids->GetId(j);
4370 //      if ( theid > id ) {
4371 //        newIds->SetId( j, theid-1 );
4372 //      } else
4373 //        newIds->SetId( j, theid );
4374 //        }
4375 //        int idSMDSel = Mactor->GetIdSMESHDSElement( i );
4376 //        Mactor->RemoveElement( idSMDSel, false );
4377 //        int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
4378 //        Mactor->AddElement( idSMDSel, idVTKel );
4379 //      }
4380 //      vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4381 //      Mapper->SetInput( newUgrid );
4382 //      Mactor->DataSource = Mapper->GetInput();
4383 //      Mactor->SetMapper(Mapper);
4384 //      UpdateView();
4385 //    }
4386 }
4387
4388 //=============================================================================
4389 /*!
4390  *
4391  */
4392 //=============================================================================
4393 void SMESHGUI::RemoveNodes(SMESH_Actor * Mactor, int number,
4394         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4395 {
4396         QApplication::setOverrideCursor(Qt::waitCursor);
4397         int i = 1;
4398         while (i <= number)
4399         {
4400                 Mactor->RemoveNode(indexes[i - 1]);
4401                 i++;
4402         }
4403
4404         TColStd_DataMapOfIntegerInteger newMapVTKNodes;
4405         TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
4406         TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
4407
4408         if (Mactor->GetMapper() != NULL)
4409         {
4410                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4411                 SMESH_Grid *newUgrid = SMESH_Grid::New();
4412                 newUgrid->CopyMaps(ugrid);
4413
4414                 vtkPoints *Pts = ugrid->GetPoints();
4415                 vtkPoints *newPts = vtkPoints::New();
4416                 int nbPts = Pts->GetNumberOfPoints();
4417                 int j = 0;
4418                 for (int i = 0; i < nbPts; i++)
4419                 {
4420                         int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
4421                         if (idSMESHDSNode != -1)
4422                         {
4423                                 newPts->InsertPoint(j, Pts->GetPoint(i));
4424
4425                                 newMapVTKNodes.Bind(j, idSMESHDSNode);
4426                                 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
4427
4428                                 MapOldNodesToNewNodes.Bind(i, j);
4429                                 j++;
4430                         }
4431                 }
4432
4433                 newUgrid->SetIdsVTKNode(newMapVTKNodes);
4434                 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
4435                 newUgrid->SetPoints(newPts);
4436
4437                 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4438                 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4439
4440                 int nbCells = ugrid->GetNumberOfCells();
4441                 for (int i = 0; i < nbCells; i++)
4442                 {
4443                         vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4444                         vtkIdList *newIds = vtkIdList::New();
4445                         int nbIds = Ids->GetNumberOfIds();
4446                         newIds->SetNumberOfIds(nbIds);
4447                         bool isGood = true;
4448                         for (int j = 0; j < nbIds; j++)
4449                         {
4450                                 int theid = Ids->GetId(j);
4451                                 if (MapOldNodesToNewNodes.IsBound(theid))
4452                                 {
4453                                         newIds->SetId(j, MapOldNodesToNewNodes.Find(theid));
4454                                 }
4455                                 else
4456                                 {
4457                                         isGood = false;
4458                                         break;
4459                                 }
4460                         }
4461
4462                         // Filtering out cells based on non-existing nodes
4463                         if (isGood)
4464                         {
4465                                 int idSMDSel = Mactor->GetIdSMESHDSElement(i);
4466                                 int idVTKel =
4467                                         newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4468                                         newIds);
4469
4470                                 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
4471                                 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
4472                         }
4473                 }
4474
4475                 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4476                 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4477
4478                 // Copy new data to the old DatSource: keep the single DataSource for all actors
4479                 ugrid->DeepCopy(newUgrid);
4480
4481                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4482                 Mapper->SetInput(ugrid);
4483                 Mactor->SetMapper(Mapper);
4484
4485                 // Commented to avoid multiple viewer updates when called by ReadScript()
4486                 //UpdateView();
4487
4488         }
4489         QApplication::restoreOverrideCursor();
4490 }
4491
4492 //=============================================================================
4493 /*!
4494  *
4495  */
4496 //=============================================================================
4497 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh,
4498         const TColStd_MapOfInteger & MapIndex)
4499 {
4500         QApplication::setOverrideCursor(Qt::waitCursor);
4501         Standard_Boolean result;
4502         SMESH_Actor *ac = FindActor(aMesh, result, true);
4503         if (result)
4504         {
4505                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4506                 anArrayOfIdeces->length(MapIndex.Extent());
4507                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4508                 int i = 0;
4509                 for (; ite.More(); ite.Next())
4510                 {
4511                         //      MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
4512                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
4513                         i++;
4514                 }
4515                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4516                 aMeshEditor->RemoveNodes(anArrayOfIdeces);
4517
4518         }
4519         if (myAutomaticUpdate)
4520         {
4521                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4522                 if (Mesh != NULL)
4523                 {
4524                         smeshGUI->DisplayActor(Mesh);
4525                         smeshGUI->DisplayEdges(Mesh);
4526                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4527                         AddActorInSelection(Mesh);
4528                 }
4529         }
4530         QApplication::restoreOverrideCursor();
4531 }
4532
4533 //=============================================================================
4534 /*!
4535  *
4536  */
4537 //=============================================================================
4538 void SMESHGUI::RemoveElement(SMESH_Actor * Mactor, int idelement)
4539 {
4540         MESSAGE(" OLD RemoveElement method ")
4541 //    int id = Mactor->GetIdVTKElement( idelement );
4542 //    MESSAGE ( " RemoveElement id VTK : " << id )
4543 //    if ( Mactor->GetMapper() != NULL ) {
4544 //      vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4545 //      vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4546 //      int nbCells = ugrid->GetNumberOfCells();
4547 //      for ( int i = 0; i < nbCells; i++ ) {
4548 //        if ( id != i ) {
4549 //      newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), 
4550 //                    ugrid->GetCell(i)->GetPointIds() );
4551 //        } else
4552 //      Mactor->RemoveElement( idelement );
4553 //      }
4554 //      newUgrid->SetPoints(ugrid->GetPoints());
4555 //      vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4556 //      Mapper->SetInput( newUgrid );
4557 //      Mactor->DataSource = Mapper->GetInput();
4558 //      Mactor->SetMapper(Mapper);
4559 //      UpdateView();
4560 //    }
4561 }
4562
4563 //=============================================================================
4564 /*!
4565  *
4566  */
4567 //=============================================================================
4568 void SMESHGUI::RemoveElements(SMESH_Actor * Mactor, int number,
4569         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4570 {
4571         QApplication::setOverrideCursor(Qt::waitCursor);
4572         int i = 1;
4573         while (i <= number)
4574         {
4575                 Mactor->RemoveElement(indexes[i - 1]);
4576                 i++;
4577         }
4578         TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4579         TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4580
4581         if (Mactor->GetMapper() != NULL)
4582         {
4583                 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4584                 SMESH_Grid *newUgrid = SMESH_Grid::New();
4585                 newUgrid->CopyMaps(ugrid);
4586
4587                 int nbCells = ugrid->GetNumberOfCells();
4588                 for (int i = 0; i < nbCells; i++)
4589                 {
4590                         int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
4591                         if (idSMESHDSElement != -1)
4592                         {
4593                                 int newId =
4594                                         newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4595                                         ugrid->GetCell(i)->GetPointIds());
4596                                 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
4597                                 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
4598                         }
4599                 }
4600
4601                 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4602                 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4603
4604                 newUgrid->SetPoints(ugrid->GetPoints());
4605
4606                 // Copy new data to the old DatSource: keep the single DataSource for all actors
4607                 ugrid->DeepCopy(newUgrid);
4608
4609                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4610                 Mapper->SetInput(ugrid);
4611                 Mactor->SetMapper(Mapper);
4612
4613                 // Commented to avoid multiple viewer updates when called by ReadScript()
4614                 //UpdateView();
4615         }
4616         QApplication::restoreOverrideCursor();
4617 }
4618
4619 //=============================================================================
4620 /*!
4621  *
4622  */
4623 //=============================================================================
4624 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh,
4625         const TColStd_MapOfInteger & MapIndex)
4626 {
4627         QApplication::setOverrideCursor(Qt::waitCursor);
4628         Standard_Boolean result;
4629         SMESH_Actor *ac = FindActor(aMesh, result, true);
4630         if (result)
4631         {
4632                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4633                 anArrayOfIdeces->length(MapIndex.Extent());
4634                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4635                 int i = 0;
4636                 for (; ite.More(); ite.Next())
4637                 {
4638                         //      MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
4639                         anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
4640                         i++;
4641                 }
4642
4643                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4644                 aMeshEditor->RemoveElements(anArrayOfIdeces);
4645         }
4646
4647         if (myAutomaticUpdate)
4648         {
4649                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4650                 if (Mesh != NULL)
4651                 {
4652                         smeshGUI->DisplayActor(Mesh);
4653                         smeshGUI->DisplayEdges(Mesh);
4654                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4655                         AddActorInSelection(Mesh);
4656 #ifdef TRACE
4657                         Dump(Mesh);
4658 #endif
4659                 }
4660         }
4661         QApplication::restoreOverrideCursor();
4662 }
4663
4664 //=============================================================================
4665 /*!
4666  *
4667  */
4668 //=============================================================================
4669 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh,
4670         const TColStd_MapOfInteger & MapIndex)
4671 {
4672         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4673                 return;
4674
4675         vtkRenderer *theRenderer =
4676                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4677                 getRightFrame()->getViewFrame())->getRenderer();
4678         Standard_Boolean result;
4679         SMESH_Actor *ac = FindActor(aMesh, result, true);
4680         if (result)
4681         {
4682                 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4683                 SMESH_Grid *UGrid = SMESH_Grid::New();
4684                 SMESH_Grid *oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
4685                 UGrid->CopyMaps(oldGrid);
4686
4687                 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4688                 gf->SetInput(ac->DataSource);
4689
4690                 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4691                 Mapper->SetInput(gf->GetOutput());
4692                 Mapper->Update();
4693
4694                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4695                 for (; ite.More(); ite.Next())
4696                 {
4697                         Mapper->GetInput()->ReverseCell(ite.Key());
4698                 }
4699
4700                 UGrid->SetPoints(Mapper->GetInput()->GetPoints());
4701                 int nbCells = Mapper->GetInput()->GetNumberOfCells();
4702                 for (int i = 0; i < nbCells; i++)
4703                 {
4704                         UGrid->InsertNextCell(Mapper->GetInput()->GetCellType(i),
4705                                 Mapper->GetInput()->GetCell(i)->GetPointIds());
4706                 }
4707
4708                 // Copy new data to the old DatSource: keep the single DataSource for all actors
4709                 oldGrid->DeepCopy(UGrid);
4710
4711                 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4712                 //NewMapper->SetInput( UGrid );
4713                 NewMapper->SetInput(oldGrid);
4714                 NewMapper->Update();
4715
4716                 //ac->DataSource = NewMapper->GetInput();
4717                 ac->SetMapper(NewMapper);
4718         }
4719         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4720         renWin->Render();
4721         QApplication::restoreOverrideCursor();
4722 }
4723
4724 //=============================================================================
4725 /*!
4726  *
4727  */
4728 //=============================================================================
4729 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh,
4730         const TColStd_MapOfInteger & MapIndex)
4731 {
4732         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4733                 return;
4734
4735         QApplication::setOverrideCursor(Qt::waitCursor);
4736         vtkRenderer *theRenderer =
4737                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4738                 getRightFrame()->getViewFrame())->getRenderer();
4739         Standard_Boolean result;
4740
4741         SMESH_Actor *ac = FindActor(aMesh, result, true);
4742         if (result)
4743         {
4744                 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4745                 SMESH_Grid *UGrid = SMESH_Grid::New();
4746                 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4747                 gf->SetInput(ac->DataSource);
4748
4749                 vtkExtractEdges *edges = vtkExtractEdges::New();
4750                 edges->SetInput(ac->DataSource);
4751
4752                 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4753                 Mapper->SetInput(edges->GetOutput());
4754                 Mapper->Update();
4755
4756                 int nb = Mapper->GetInput()->GetNumberOfCells();
4757                 //MESSAGE ( "nb : " << nb )
4758
4759                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4760                 for (; ite.More(); ite.Next())
4761                 {
4762                         vtkCell *StartEdge = Mapper->GetInput()->GetCell(ite.Key());
4763                         //MESSAGE( "DCQ : Edge Id = " << ite.Key())
4764                         int CellType = StartEdge->GetCellType();
4765                         //MESSAGE( "DCQ : Cell Type = " << CellType)
4766                         int nbPoints = StartEdge->GetNumberOfPoints();
4767
4768                         //MESSAGE( "DCQ : Nb Point = " << nbPoints)
4769                         if (nbPoints == 2)
4770                         {
4771                                 vtkUnstructuredGrid *StartUGrid =
4772                                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
4773
4774                                 vtkIdList *IdCells = vtkIdList::New();
4775                                 vtkIdList *IdPoints = StartEdge->GetPointIds();
4776                                 float p1[3];
4777                                 float p2[3];
4778
4779                                 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),
4780                                         p1);
4781                                 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),
4782                                         p2);
4783
4784                                 int idp1 = StartUGrid->FindPoint(p1);
4785                                 int idp2 = StartUGrid->FindPoint(p2);
4786
4787                                 StartUGrid->GetPointCells(idp1, IdCells);
4788
4789                                 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4790                                 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4791
4792                                 //MESSAGE ( " pt 0 : " << idp1 )
4793                                 //MESSAGE ( " pt 1 : " << idp2 )
4794
4795                                 vtkIdList *IdPts = vtkIdList::New();
4796                                 if (IdCells->GetNumberOfIds() >= 2)
4797                                 {
4798                                         int nbCells = IdCells->GetNumberOfIds();
4799                                         //MESSAGE ( " nbCells : " << nbCells )
4800                                         for (int j = 0; j < nbCells; j++)
4801                                         {
4802                                                 StartUGrid->GetCellPoints(IdCells->GetId(j), IdPts);
4803                                                 if (IdPts->IsId(idp2) == -1)
4804                                                 {
4805                                                         IdCells->DeleteId(IdCells->GetId(j));
4806                                                 }
4807                                         }
4808
4809                                         //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4810
4811                                         vtkIdList *IdPts0 = vtkIdList::New();
4812                                         vtkIdList *IdPts1 = vtkIdList::New();
4813
4814                                         if (IdCells->GetNumberOfIds() == 2)
4815                                         {
4816                                                 StartUGrid->GetCellPoints(IdCells->GetId(0), IdPts0);
4817                                                 StartUGrid->GetCellPoints(IdCells->GetId(1), IdPts1);
4818
4819                                                 //Create new faces
4820                                                 TColStd_MapOfInteger EndMapIndex;
4821                                                 for (int j = 0; j < 3; j++)
4822                                                 {
4823                                                         if (IdPts0->GetId(j) != idp1 &&
4824                                                                 IdPts0->GetId(j) != idp2)
4825                                                         {
4826                                                                 EndMapIndex.Add(IdPts0->GetId(j));
4827                                                         }
4828                                                         if (IdPts1->GetId(j) != idp1 &&
4829                                                                 IdPts1->GetId(j) != idp2)
4830                                                         {
4831                                                                 EndMapIndex.Add(IdPts1->GetId(j));
4832                                                         }
4833                                                 }
4834
4835                                                 bool MyAU = myAutomaticUpdate;
4836                                                 myAutomaticUpdate = false;
4837
4838                                                 EndMapIndex.Add(idp1);
4839                                                 TColStd_MapIteratorOfMapOfInteger ite1(EndMapIndex);
4840                                                 int i = 1;
4841                                                 while (ite1.More())
4842                                                 {
4843                                                         if (ite1.Key() == idp1)
4844                                                                 break;
4845                                                         i++;
4846                                                         ite1.Next();
4847                                                 }
4848                                                 bool reverse1 = (i == 2);
4849                                                 this->AddFace(aMesh, EndMapIndex, reverse1);
4850
4851                                                 EndMapIndex.Remove(idp1);
4852                                                 EndMapIndex.Add(idp2);
4853                                                 TColStd_MapIteratorOfMapOfInteger ite2(EndMapIndex);
4854                                                 i = 1;
4855                                                 while (ite2.More())
4856                                                 {
4857                                                         if (ite2.Key() == idp2)
4858                                                                 break;
4859                                                         i++;
4860                                                         ite2.Next();
4861                                                 }
4862                                                 bool reverse2 = (i == 2);
4863                                                 this->AddFace(aMesh, EndMapIndex,
4864                                                         !(reverse1 == reverse2));
4865
4866                                                 myAutomaticUpdate = MyAU;
4867                                                 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4868                                                 Mapper->Update();
4869                                                 //Remove old faces
4870                                                 TColStd_MapOfInteger StartMapIndex;
4871                                                 StartMapIndex.Add(IdCells->GetId(0));
4872                                                 StartMapIndex.Add(IdCells->GetId(1));
4873                                                 this->RemoveElements(aMesh, StartMapIndex);
4874
4875                                                 Mapper->Update();
4876                                         }
4877                                 }
4878                         }
4879                 }
4880
4881                 //      UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4882                 //      int nbCells = Mapper->GetInput()->GetNumberOfCells();
4883                 //      for ( int i = 0; i < nbCells; i++ ) {
4884                 //        UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4885                 //      }
4886
4887                 //      vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4888                 //      NewMapper->SetInput( UGrid );
4889                 //      NewMapper->Update();
4890
4891                 //      ac->DataSource = NewMapper->GetInput();
4892                 //      ac->SetMapper( NewMapper );
4893         }
4894         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4895         renWin->Render();
4896         QApplication::restoreOverrideCursor();
4897 }
4898
4899 //=============================================================================
4900 /*!
4901  *
4902  */
4903 //=============================================================================
4904 void SMESHGUI::AddEdges(SMESH_Actor * Mactor, int number,
4905         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4906 {
4907         QApplication::setOverrideCursor(Qt::waitCursor);
4908         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4909         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4910         int i = 1;
4911         int j = 1;
4912         while (i <= number)
4913         {
4914                 vtkIdList *Ids = vtkIdList::New();
4915                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
4916                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
4917                 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4918                 Mactor->AddElement(indexes[j - 1], id);
4919                 i++;
4920                 j = j + 3;
4921         }
4922         vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4923         EdgeMapper->SetInput(ugrid);
4924         Mactor->DataSource = EdgeMapper->GetInput();
4925         Mactor->SetMapper(EdgeMapper);
4926         QApplication::restoreOverrideCursor();
4927 }
4928
4929 //=============================================================================
4930 /*!
4931  *
4932  */
4933 //=============================================================================
4934 void SMESHGUI::AddEdge(SMESH_Actor * Mactor, int idedge, int idnode1,
4935         int idnode2)
4936 {
4937         QApplication::setOverrideCursor(Qt::waitCursor);
4938         MESSAGE("SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" <<
4939                 idnode2) vtkIdList *Ids = vtkIdList::New();
4940         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
4941         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
4942
4943         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4944         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4945         int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4946         Mactor->AddElement(idedge, id);
4947
4948         MESSAGE(" Edge VTK id " << id)
4949                 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4950         EdgeMapper->SetInput(ugrid);
4951         Mactor->DataSource = EdgeMapper->GetInput();
4952         Mactor->SetMapper(EdgeMapper);
4953         QApplication::restoreOverrideCursor();
4954 }
4955
4956 //=============================================================================
4957 /*!
4958  *
4959  */
4960 //=============================================================================
4961 void SMESHGUI::AddTriangles(SMESH_Actor * Mactor, int number,
4962         const SMESH::double_array & coords, const SMESH::long_array & indexes)
4963 {
4964 //      MESSAGE("SMESHGUI::AddTriangles(number="<<number<<", indexes.length="
4965 //              <<indexes.length()<<")");
4966
4967         QApplication::setOverrideCursor(Qt::waitCursor);
4968         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4969         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4970         int i = 1;
4971         int j = 1;
4972         while (i <= number)
4973         {
4974                 vtkIdList *Ids = vtkIdList::New();
4975                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
4976                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
4977                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
4978                 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4979                 Mactor->AddElement(indexes[j - 1], id);
4980                 i++;
4981                 j = j + 4;
4982         }
4983         vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4984         TriMapper->SetInput(ugrid);
4985         Mactor->DataSource = TriMapper->GetInput();
4986         Mactor->SetMapper(TriMapper);
4987         QApplication::restoreOverrideCursor();
4988 }
4989 void SMESHGUI::AddTriangle(SMESH_Actor * Mactor, int idtri, int idnode1,
4990         int idnode2, int idnode3)
4991 {
4992         QApplication::setOverrideCursor(Qt::waitCursor);
4993         vtkIdList *Ids = vtkIdList::New();
4994         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
4995         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
4996         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
4997
4998         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4999         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5000         int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
5001         Mactor->AddElement(idtri, id);
5002
5003         vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
5004         TriMapper->SetInput(ugrid);
5005         Mactor->DataSource = TriMapper->GetInput();
5006         Mactor->SetMapper(TriMapper);
5007         QApplication::restoreOverrideCursor();
5008 }
5009
5010 //=============================================================================
5011 /*!
5012  *
5013  */
5014 //=============================================================================
5015 void SMESHGUI::AddQuadrangles(SMESH_Actor * Mactor, int number,
5016         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5017 {
5018         QApplication::setOverrideCursor(Qt::waitCursor);
5019         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5020         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5021         int i = 1;
5022         int j = 1;
5023         while (i <= number)
5024         {
5025                 vtkIdList *Ids = vtkIdList::New();
5026                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5027                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5028                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5029                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5030                 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5031                 Mactor->AddElement(indexes[j - 1], id);
5032                 i++;
5033                 j = j + 5;
5034         }
5035         vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5036         QuadMapper->SetInput(ugrid);
5037         Mactor->DataSource = QuadMapper->GetInput();
5038         Mactor->SetMapper(QuadMapper);
5039         QApplication::restoreOverrideCursor();
5040 }
5041
5042 //=============================================================================
5043 /*!
5044  *
5045  */
5046 //=============================================================================
5047 void SMESHGUI::AddQuadrangle(SMESH_Actor * Mactor, int idquad, int idnode1,
5048         int idnode2, int idnode3, int idnode4)
5049 {
5050         QApplication::setOverrideCursor(Qt::waitCursor);
5051         vtkIdList *Ids = vtkIdList::New();
5052         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5053         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5054         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5055         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5056
5057         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5058         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5059         int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5060         Mactor->AddElement(idquad, id);
5061
5062         vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5063         QuadMapper->SetInput(ugrid);
5064         Mactor->DataSource = QuadMapper->GetInput();
5065         Mactor->SetMapper(QuadMapper);
5066         QApplication::restoreOverrideCursor();
5067 }
5068
5069 //=============================================================================
5070 /*!
5071  *
5072  */
5073 //=============================================================================
5074 void SMESHGUI::AddTetras(SMESH_Actor * Mactor, int number,
5075         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5076 {
5077         QApplication::setOverrideCursor(Qt::waitCursor);
5078         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5079         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5080         int i = 1;
5081         int j = 1;
5082         while (i <= number)
5083         {
5084                 vtkIdList *Ids = vtkIdList::New();
5085                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5086                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5087                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5088                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5089                 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5090                 Mactor->AddElement(indexes[j - 1], id);
5091                 i++;
5092                 j = j + 5;
5093         }
5094         vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5095         TetraMapper->SetInput(ugrid);
5096         Mactor->DataSource = TetraMapper->GetInput();
5097         Mactor->SetMapper(TetraMapper);
5098         QApplication::restoreOverrideCursor();
5099 }
5100
5101 //=============================================================================
5102 /*!
5103  *
5104  */
5105 //=============================================================================
5106 void SMESHGUI::AddTetra(SMESH_Actor * Mactor, int idtetra, int idnode1,
5107         int idnode2, int idnode3, int idnode4)
5108 {
5109         QApplication::setOverrideCursor(Qt::waitCursor);
5110         MESSAGE("SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" <<
5111                 idnode2 << ";" << idnode3 << ";" << idnode4) vtkIdList *Ids =
5112                 vtkIdList::New();
5113         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5114         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5115         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5116         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5117
5118         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5119         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5120         int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5121         Mactor->AddElement(idtetra, id);
5122
5123         MESSAGE(" Tetra VTK id " << id)
5124                 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5125         TetraMapper->SetInput(ugrid);
5126         Mactor->DataSource = TetraMapper->GetInput();
5127         Mactor->SetMapper(TetraMapper);
5128         QApplication::restoreOverrideCursor();
5129 }
5130
5131 //=============================================================================
5132 /*!
5133  *
5134  */
5135 //=============================================================================
5136 void SMESHGUI::AddHexaedres(SMESH_Actor * Mactor, int number,
5137         const SMESH::double_array & coords, const SMESH::long_array & indexes)
5138 {
5139         QApplication::setOverrideCursor(Qt::waitCursor);
5140         //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5141         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5142         int i = 1;
5143         int j = 1;
5144         while (i <= number)
5145         {
5146                 vtkIdList *Ids = vtkIdList::New();
5147                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5148                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5149                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5150                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5151                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 4]));
5152                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 5]));
5153                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 6]));
5154                 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 7]));
5155                 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5156                 Mactor->AddElement(indexes[j - 1], id);
5157                 i++;
5158                 j = j + 9;
5159         }
5160         vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5161         HexaMapper->SetInput(ugrid);
5162         Mactor->DataSource = HexaMapper->GetInput();
5163         Mactor->SetMapper(HexaMapper);
5164         QApplication::restoreOverrideCursor();
5165 }
5166
5167 //=============================================================================
5168 /*!
5169  *
5170  */
5171 //=============================================================================
5172 void SMESHGUI::AddHexaedre(SMESH_Actor * Mactor, int idhexa, int idnode1,
5173         int idnode2, int idnode3, int idnode4, int idnode5, int idnode6,
5174         int idnode7, int idnode8)
5175 {
5176         QApplication::setOverrideCursor(Qt::waitCursor);
5177         MESSAGE("SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" <<
5178                 idnode2 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" <<
5179                 idnode6 << ";" << idnode7 << ";" << idnode8) vtkIdList *Ids =
5180                 vtkIdList::New();
5181         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5182         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5183         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5184         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5185         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode5));
5186         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode6));
5187         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode7));
5188         Ids->InsertNextId(Mactor->GetIdVTKNode(idnode8));
5189
5190         //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5191         SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5192         int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5193         Mactor->AddElement(idhexa, id);
5194
5195         MESSAGE(" Hexa VTK id " << id)
5196                 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5197         HexaMapper->SetInput(ugrid);
5198         Mactor->DataSource = HexaMapper->GetInput();
5199         Mactor->SetMapper(HexaMapper);
5200         QApplication::restoreOverrideCursor();
5201 }
5202
5203 //=====================================================================================
5204 // EXPORTED METHODS
5205 //=====================================================================================
5206 extern "C"
5207 {
5208         bool OnGUIEvent(int theCommandID, QAD_Desktop * parent)
5209         {
5210                 return SMESHGUI::OnGUIEvent(theCommandID, parent);
5211         }
5212
5213         bool OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
5214                 QAD_StudyFrame * studyFrame)
5215         {
5216                 return SMESHGUI::OnKeyPress(pe, parent, studyFrame);
5217         }
5218
5219         bool OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
5220                 QAD_StudyFrame * studyFrame)
5221         {
5222                 return SMESHGUI::OnMousePress(pe, parent, studyFrame);
5223         }
5224
5225         bool OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
5226                 QAD_StudyFrame * studyFrame)
5227         {
5228                 return SMESHGUI::OnMouseMove(pe, parent, studyFrame);
5229         }
5230
5231         bool SetSettings(QAD_Desktop * parent)
5232         {
5233                 return SMESHGUI::SetSettings(parent);
5234         }
5235
5236         bool customPopup(QAD_Desktop * parent, QPopupMenu * popup,
5237                 const QString & theContext, const QString & theParent,
5238                 const QString & theObject)
5239         {
5240                 return SMESHGUI::CustomPopup(parent, popup, theContext, theParent,
5241                         theObject);
5242         }
5243
5244         void definePopup(QString & theContext, QString & theParent,
5245                 QString & theObject)
5246         {
5247                 SMESHGUI::DefinePopup(theContext, theParent, theObject);
5248         }
5249
5250         bool activeStudyChanged(QAD_Desktop * parent)
5251         {
5252                 SMESHGUI::activeStudyChanged(parent);
5253         }
5254
5255         void buildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
5256         {
5257                 SMESHGUI::BuildPresentation(theIO);
5258         }
5259
5260         void supportedViewType(int *buffer, int bufferSize)
5261         {
5262                 if (!buffer || !bufferSize)
5263                         return;
5264                 buffer[0] = (int)VIEW_VTK;
5265         }
5266
5267 }
5268
5269 //=============================================================================
5270 /*!
5271  *
5272  */
5273 //=============================================================================
5274 void SMESHGUI::ViewNodes()
5275 {
5276         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5277                 return;
5278
5279         EraseSimulationActors();
5280         mySimulationActors = vtkActorCollection::New();
5281         vtkRenderer *theRenderer =
5282                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5283                 getRightFrame()->getViewFrame())->getRenderer();
5284         vtkActorCollection *theActors = theRenderer->GetActors();
5285         theActors->InitTraversal();
5286         vtkActor *ac = theActors->GetNextActor();
5287         while (!(ac == NULL))
5288         {
5289                 if (ac->IsA("SMESH_Actor"))
5290                 {
5291                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
5292                         if (anActor->GetVisibility() == 1)
5293                         {
5294                                 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5295                                 gf->SetInput(anActor->DataSource);
5296                                 vtkMaskPoints *verts = vtkMaskPoints::New();
5297                                 verts->SetInput(gf->GetOutput());
5298                                 verts->GenerateVerticesOn();
5299                                 verts->SetOnRatio(1);
5300
5301                                 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
5302                                 vertMapper->SetInput(verts->GetOutput());
5303                                 vertMapper->ScalarVisibilityOff();
5304
5305                                 vtkActor *vertActor = vtkActor::New();
5306                                 vertActor->SetMapper(vertMapper);
5307
5308                                 float r, g, b;
5309                                 anActor->GetNodeColor(r, g, b);
5310                                 vertActor->GetProperty()->SetColor(r, g, b);
5311
5312                                 vertActor->GetProperty()->SetPointSize(anActor->GetNodeSize());
5313
5314                                 vertActor->PickableOff();
5315
5316                                 mySimulationActors->AddItem(vertActor);
5317                                 theRenderer->AddActor(vertActor);
5318                         }
5319                 }
5320                 ac = theActors->GetNextActor();
5321         }
5322
5323         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5324         renWin->Render();
5325 }
5326
5327 //=============================================================================
5328 /*!
5329  *
5330  */
5331 //=============================================================================
5332 void SMESHGUI::Control(int theCommandID)
5333 {
5334         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5335                 return;
5336
5337         QApplication::setOverrideCursor(Qt::waitCursor);
5338         DisplayScalarBar(false);
5339
5340         vtkDoubleArray *scalars = vtkDoubleArray::New();
5341         scalars->SetNumberOfComponents(1);
5342
5343         vtkDataSetMapper *meshMapper = 0;
5344         SALOME_Selection *Sel =
5345                 SALOME_Selection::Selection(myActiveStudy->getSelection());
5346         int nbSel = Sel->IObjectCount();
5347         Standard_Boolean result;
5348         Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
5349         SMESH_Actor *MeshActor =
5350                 FindActorByEntry(IObject->getEntry(), result, true);
5351
5352         // Mesh may be not updated after Compute
5353         if (!MeshActor->DataSource || !MeshActor->GetMapper())
5354         {
5355                 QApplication::restoreOverrideCursor();
5356                 return;
5357         }
5358
5359         vtkDataSet *aDataSet = MeshActor->DataSource;
5360         typedef double (*TScalarFun) (vtkCell * theCell);
5361         TScalarFun aScalarFun;
5362         if (result)
5363         {
5364                 QString type;
5365                 switch (theCommandID)
5366                 {
5367                 case 6001:
5368                 {
5369                         type = tr("SMESH_CONTROL_LENGTH_EDGES");
5370                         aDataSet = MeshActor->EdgeDevice->GetMapper()->GetInput();
5371                         aScalarFun = &(SMESHGUI_ComputeScalarValue::LengthEdges);
5372                         MESSAGE(" init minimum length " << aDataSet->GetNumberOfCells());
5373                         if (MeshActor->getDisplayMode() != 0)
5374                                 ChangeRepresentation(MeshActor, 1);     // limitation; in Wireframe, colored edges are not visible
5375                         break;
5376                 }
5377                 case 6011:
5378                 {
5379                         type = tr("SMESH_CONTROL_AREA_ELEMENTS");
5380                         aScalarFun = &(SMESHGUI_ComputeScalarValue::AreaElements);
5381                         if (MeshActor->getDisplayMode() != 1)
5382                                 ChangeRepresentation(MeshActor, 1);
5383                         break;
5384                 }
5385                 case 6012:
5386                 {
5387                         type = tr("SMESH_CONTROL_TAPER_ELEMENTS");
5388                         aScalarFun = &(SMESHGUI_ComputeScalarValue::Taper);
5389                         break;
5390                 }
5391                 case 6013:
5392                 {
5393                         type = tr("SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
5394                         aScalarFun = &(SMESHGUI_ComputeScalarValue::AspectRatio);
5395                         if (MeshActor->getDisplayMode() != 1)
5396                                 ChangeRepresentation(MeshActor, 1);
5397                         break;
5398                 }
5399                 case 6014:
5400                 {
5401                         type = tr("SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
5402                         aScalarFun = &(SMESHGUI_ComputeScalarValue::MinimumAngle);
5403                         if (MeshActor->getDisplayMode() != 1)
5404                                 ChangeRepresentation(MeshActor, 1);
5405                         break;
5406                 }
5407                 case 6015:
5408                 {
5409                         type = tr("SMESH_CONTROL_WARP_ELEMENTS");
5410                         aScalarFun = &(SMESHGUI_ComputeScalarValue::Warp);
5411                         break;
5412                 }
5413                 case 6016:
5414                 {
5415                         type = tr("SMESH_CONTROL_SKEW_ELEMENTS");
5416                         aScalarFun = &(SMESHGUI_ComputeScalarValue::Skew);
5417                         break;
5418                 }
5419                 }
5420
5421                 for (int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++)
5422                         scalars->InsertTuple1(i, aScalarFun(aDataSet->GetCell(i)));
5423
5424                 float range[2];
5425                 scalars->GetRange(range);
5426
5427                 vtkLookupTable *wat = vtkLookupTable::New();
5428                 wat->SetRange(range);
5429                 wat->Build();
5430
5431                 scalars->SetLookupTable(wat);
5432
5433                 if (!meshMapper)
5434                         meshMapper = (vtkDataSetMapper *) (MeshActor->getMapper());
5435                 meshMapper->SetScalarModeToUseCellData();
5436                 MeshActor->DataSource->GetCellData()->SetScalars(scalars);
5437                 meshMapper->SetScalarRange(range);
5438                 meshMapper->ScalarVisibilityOn();
5439
5440                 vtkScalarBarActor *aScalarBar = GetScalarBar();
5441                 if (aScalarBar == NULL)
5442                 {
5443                         aScalarBar = vtkScalarBarActor::New();
5444                         QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
5445                         QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
5446                         QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
5447                         QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
5448                         QString Orientation =
5449                                 QAD_CONFIG->getSetting("ScalarBar:Orientation");
5450                         float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
5451                         float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
5452                         int NumberOfLabels =
5453                                 QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
5454                         int NumberOfColors =
5455                                 QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
5456
5457                         SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily,
5458                                 Orientation, Width, Height, NumberOfColors, NumberOfLabels);
5459                         vtkRenderer *theRenderer =
5460                                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5461                                 getRightFrame()->getViewFrame())->getRenderer();
5462                         theRenderer->AddActor2D(aScalarBar);
5463                 }
5464                 aScalarBar->SetLookupTable(wat);
5465                 aScalarBar->SetTitle(type.latin1());
5466
5467                 scalars->Delete();
5468                 //    wat->Delete();
5469                 DisplayScalarBar(true);
5470         }
5471         QApplication::restoreOverrideCursor();
5472 }
5473
5474 //=============================================================================
5475 /*!
5476  *
5477  */
5478 //=============================================================================
5479 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor * theScalarBar,
5480         QString Bold, QString Italic,
5481         QString Shadow, QString FontFamily,
5482         QString Orientation, float Width, float Height, int NbColors, int NbLabels)
5483 {
5484         if (Bold.isNull() || Bold.isEmpty() || (Bold.compare("true") == 0))
5485                 theScalarBar->BoldOn();
5486         else
5487                 theScalarBar->BoldOff();
5488
5489         if (Italic.isNull() || Italic.isEmpty() || (Italic.compare("true") == 0))
5490                 theScalarBar->ItalicOn();
5491         else
5492                 theScalarBar->ItalicOff();
5493
5494         if (Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare("true") == 0))
5495                 theScalarBar->ShadowOn();
5496         else
5497                 theScalarBar->ShadowOff();
5498
5499         if (FontFamily.compare("Arial") == 0)
5500                 theScalarBar->SetFontFamilyToArial();
5501         else if (FontFamily.compare("Courier") == 0)
5502                 theScalarBar->SetFontFamilyToCourier();
5503         else if (FontFamily.compare("Times") == 0)
5504                 theScalarBar->SetFontFamilyToTimes();
5505         else
5506                 theScalarBar->SetFontFamilyToArial();
5507
5508         if (Orientation.isNull() || Orientation.isEmpty() ||
5509                 (Orientation.compare("Vertical") == 0))
5510                 theScalarBar->SetOrientationToVertical();
5511         else
5512                 theScalarBar->SetOrientationToHorizontal();
5513
5514         theScalarBar->SetWidth((Width == 0) ? 0.17 : Width);
5515         theScalarBar->SetHeight((Height == 0) ? 0.8 : Height);
5516
5517         theScalarBar->SetNumberOfLabels((NbLabels == 0) ? 5 : NbLabels);
5518         theScalarBar->SetMaximumNumberOfColors((NbColors == 0) ? 64 : NbColors);
5519 }
5520
5521 //=============================================================================
5522 /*!
5523  *
5524  */
5525 //=============================================================================
5526 void SMESHGUI::DisplayScalarBar(bool visibility)
5527 {
5528         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5529                 return;
5530
5531         vtkRenderer *theRenderer =
5532                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5533                 getRightFrame()->getViewFrame())->getRenderer();
5534         vtkScalarBarActor *aScalarBar = GetScalarBar();
5535
5536         if (aScalarBar == NULL)
5537         {
5538                 MESSAGE("myScalarBar is NULL");
5539                 return;
5540         }
5541
5542         if (visibility)
5543                 aScalarBar->VisibilityOn();
5544         else
5545         {
5546                 aScalarBar->VisibilityOff();
5547                 //Turn off mesh coloring (influences on all views)
5548                 vtkActorCollection *actorList = theRenderer->GetActors();
5549                 actorList->InitTraversal();
5550                 vtkActor *ac = actorList->GetNextActor();
5551                 while (ac != NULL)
5552                 {
5553                         if (ac->GetMapper() != NULL)
5554                         {
5555                                 ac->GetMapper()->ScalarVisibilityOff();
5556                         }
5557                         ac = actorList->GetNextActor();
5558                 }
5559                 // Turn off ScalarBar in all views
5560                 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
5561                  * for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
5562                  * if (aFrame->getTypeView() == VIEW_VTK) {
5563                  * vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
5564                  * vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
5565                  * actor2DList->InitTraversal();
5566                  * vtkActor2D* aActor2d =  actor2DList->GetNextActor2D();
5567                  * while (aActor2d != NULL) {
5568                  * if (aActor2d->IsA("vtkScalarBarActor")) {
5569                  * aActor2d->VisibilityOff();
5570                  * break;
5571                  * }
5572                  * actor2DList->GetNextActor2D();
5573                  * }
5574                  * }
5575                  * } */
5576         }
5577         myActiveStudy->update3dViewers();
5578 }
5579
5580 //=============================================================================
5581 /*!
5582  *
5583  */
5584 //=============================================================================
5585 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
5586 {
5587         vtkScalarBarActor *aScalarBar = GetScalarBar();
5588         if (aScalarBar == NULL)
5589         {
5590                 MESSAGE("myScalarBar is NULL");
5591                 return;
5592         }
5593         DisplayScalarBar(false);
5594
5595         aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
5596         vtkRenderer *aRenderer =
5597                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5598                 getRightFrame()->getViewFrame())->getRenderer();
5599         vtkActorCollection *aActorList = aRenderer->GetActors();
5600         aActorList->InitTraversal();
5601         vtkActor *aActor = aActorList->GetNextActor();
5602         while (aActor != NULL)
5603         {
5604                 if (aActor->IsA("SMESH_Actor"))
5605                 {
5606                         SMESH_Actor *aMeshActor = SMESH_Actor::SafeDownCast(aActor);
5607                         vtkDataSetMapper *aMeshMapper =
5608                                 (vtkDataSetMapper *) (aMeshActor->getMapper());
5609                         if ((aMeshMapper != NULL))
5610                         {
5611                                 aMeshMapper->SetScalarRange(MinRange, MaxRange);
5612                                 aMeshMapper->ScalarVisibilityOn();
5613                         }
5614                 }
5615                 aActor = aActorList->GetNextActor();
5616         }
5617         DisplayScalarBar(true);
5618 }
5619
5620 //=============================================================================
5621 /*!
5622  *
5623  */
5624 //=============================================================================
5625 void SMESHGUI::SetDisplaySettings()
5626 {
5627         EmitSignalDeactivateDialog();
5628         SMESHGUI_Preferences_ColorDlg *aDlg =
5629                 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
5630
5631         QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
5632         QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
5633         QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
5634         QColor color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5635         aDlg->SetColor(1, color);
5636
5637         SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
5638         SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
5639         SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
5640         color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5641         aDlg->SetColor(2, color);
5642
5643         SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5644         SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5645         SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5646         color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5647         aDlg->SetColor(3, color);
5648
5649         QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
5650         QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
5651         QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
5652         color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
5653         aDlg->SetColor(4, color);
5654
5655         QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
5656         aDlg->SetIntValue(1, intValue.toInt());
5657         intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
5658         aDlg->SetIntValue(2, intValue.toInt());
5659         intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
5660         aDlg->SetIntValue(3, intValue.toInt());
5661
5662         if (aDlg->exec())
5663         {
5664                 QColor colorFill = aDlg->GetColor(1);
5665                 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
5666                 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen",
5667                         colorFill.green());
5668                 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
5669
5670                 QColor colorOutline = aDlg->GetColor(2);
5671                 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed",
5672                         colorOutline.red());
5673                 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen",
5674                         colorOutline.green());
5675                 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue",
5676                         colorOutline.blue());
5677
5678                 QColor colorNode = aDlg->GetColor(3);
5679                 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
5680                 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen",
5681                         colorNode.green());
5682                 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
5683
5684                 QColor colorBackFace = aDlg->GetColor(4);
5685                 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed",
5686                         colorBackFace.red());
5687                 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen",
5688                         colorBackFace.green());
5689                 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue",
5690                         colorBackFace.blue());
5691
5692                 int width = aDlg->GetIntValue(1);
5693                 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
5694
5695                 int nodes_size = aDlg->GetIntValue(2);
5696                 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
5697
5698                 int shrink_coeff = aDlg->GetIntValue(3);
5699                 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
5700         }
5701
5702         delete aDlg;
5703 }
5704
5705 //=======================================================================
5706 // function : Parameter()
5707 // purpose  : return a parameter (double) from a dialog box
5708 //
5709 //  aValue     : is a double used as a default value displayed
5710 //  aLabel     : is the title for aValue1
5711 //  aTitle     : is the main title
5712 //  bottom     : maximum value to be entered
5713 //  top        : minimum value to be entered
5714 //  decimals   : number of decimals
5715 //=======================================================================
5716 double SMESHGUI::Parameter(Standard_Boolean & res,
5717         const double aValue,
5718         const char *aLabel,
5719         const char *aTitle,
5720         const double bottom, const double top, const int decimals)
5721 {
5722         SMESHGUI_aParameterDlg *Dialog =
5723                 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5724                 aTitle,
5725                 aLabel,
5726                 bottom, top, decimals,
5727                 TRUE);
5728         Dialog->setValue(aValue);
5729         double X = 0.0;
5730         res = (Dialog->exec() == QDialog::Accepted);
5731         if (res)
5732                 X = Dialog->getDblValue();
5733         return X;
5734 }
5735
5736 //=======================================================================
5737 // function : Parameter()
5738 // purpose  : return a parameter (int) from a dialog box
5739 //
5740 //  aValue     : is a int used as a default value displayed
5741 //  aLabel     : is the title for aValue1
5742 //  aTitle     : is the main title
5743 //  bottom     : maximum value to be entered
5744 //  top        : minimum value to be entered
5745 //=======================================================================
5746 int SMESHGUI::Parameter(Standard_Boolean & res,
5747         const int aValue,
5748         const char *aLabel, const char *aTitle, const int bottom, const int top)
5749 {
5750         SMESHGUI_aParameterDlg *Dialog =
5751                 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5752                 aTitle,
5753                 aLabel,
5754                 bottom, top,
5755                 TRUE);
5756         Dialog->setValue(aValue);
5757         int X = 0;
5758         res = (Dialog->exec() == QDialog::Accepted);
5759         if (res)
5760                 X = Dialog->getIntValue();
5761         return X;
5762 }
5763
5764 //=============================================================================
5765 /*!
5766  *
5767  */
5768 //=============================================================================
5769 void SMESHGUI::DisplayEdges(SMESH_Actor * ac, bool visibility)
5770 {
5771         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5772                 return;
5773         if (ac->DataSource == NULL || ac->GetMapper() == NULL)
5774                 return;
5775
5776         vtkGeometryFilter *gf = vtkGeometryFilter::New();
5777         gf->SetInput(ac->DataSource);
5778         vtkFeatureEdges *edges = vtkFeatureEdges::New();
5779         edges->SetInput(gf->GetOutput());
5780         edges->BoundaryEdgesOn();
5781         edges->ManifoldEdgesOn();
5782
5783         vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5784         edgeMapper->SetInput(edges->GetOutput());
5785         edgeMapper->ScalarVisibilityOff();
5786
5787         vtkRenderer *theRenderer =
5788                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5789                 getRightFrame()->getViewFrame())->getRenderer();
5790         vtkActorCollection *actorList = theRenderer->GetActors();
5791
5792         int test = actorList->IsItemPresent(ac->EdgeDevice);
5793         if (test == 0)
5794         {
5795                 vtkProperty *prop = vtkProperty::New();
5796                 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5797                         toFloat() / 255.,
5798                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5799                         toFloat() / 255.,
5800                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5801                         255.);
5802                 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5803                         toInt());
5804                 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5805                         toInt());
5806                 ac->EdgeDevice->SetProperty(prop);
5807                 ac->SetEdgeColor(QAD_CONFIG->
5808                         getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5809                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5810                         toFloat() / 255.,
5811                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5812                         255.);
5813                 ac->EdgeDevice->SetMapper(edgeMapper);
5814
5815                 theRenderer->AddActor(ac->EdgeDevice);
5816         }
5817         else
5818         {
5819                 ac->EdgeDevice->SetMapper(edgeMapper);
5820                 edgeMapper->Update();
5821         }
5822
5823         vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5824         shrink->SetInput(ac->DataSource);
5825         shrink->SetShrinkFactor(ac->GetShrinkFactor());
5826         vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5827         Shrinkgf->SetInput(shrink->GetOutput());
5828         vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5829         ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5830         ShrinkEdges->BoundaryEdgesOn();
5831         ShrinkEdges->ManifoldEdgesOn();
5832
5833         vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5834         ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5835         ShrinkEdgeMapper->ScalarVisibilityOff();
5836
5837         test = actorList->IsItemPresent(ac->EdgeShrinkDevice);
5838         if (test == 0)
5839         {
5840                 vtkProperty *prop = vtkProperty::New();
5841                 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5842                         toFloat() / 255.,
5843                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5844                         toFloat() / 255.,
5845                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5846                         255.);
5847                 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5848                         toInt());
5849                 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5850                         toInt());
5851                 ac->EdgeShrinkDevice->SetProperty(prop);
5852                 ac->SetEdgeColor(QAD_CONFIG->
5853                         getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5854                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5855                         toFloat() / 255.,
5856                         QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5857                         255.);
5858                 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5859
5860                 theRenderer->AddActor(ac->EdgeShrinkDevice);
5861         }
5862         else
5863         {
5864                 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5865                 ShrinkEdgeMapper->Update();
5866         }
5867
5868         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5869         renWin->Render();
5870 }
5871
5872 //=============================================================================
5873 /*!
5874  *
5875  */
5876 //=============================================================================
5877 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5878 {
5879         SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh(aMesh);
5880         SALOMEDS::GenericAttribute_var anAttr;
5881         SALOMEDS::AttributeName_var aName;
5882         if (!aSO_M->_is_nil())
5883         {
5884                 if (aSO_M->FindAttribute(anAttr, "AttributeName"))
5885                 {
5886                         aName = SALOMEDS::AttributeName::_narrow(anAttr);
5887                         Standard_Boolean result;
5888                         SMESH_Actor *MeshActor =
5889                                 smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5890                         if (!result)
5891                         {
5892                                 SMESH_Actor *amesh = SMESH_Actor::New();
5893                                 Handle(SALOME_InteractiveObject) IO =
5894                                         new SALOME_InteractiveObject(aSO_M->GetID(), "MESH",
5895                                         aName->Value());
5896                                 amesh->setIO(IO);
5897                                 amesh->setName(aName->Value());
5898                                 DisplayActor(amesh, false);
5899                         }
5900                 }
5901         }
5902 }
5903
5904 //=============================================================================
5905 /*!
5906  *
5907  */
5908 //=============================================================================
5909 void SMESHGUI::Update()
5910 {
5911         MESSAGE("SMESHGUI::Update");
5912         if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
5913         {                                                       //VTK
5914                 vtkRenderer *theRenderer =
5915                         ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5916                         getRightFrame()->getViewFrame())->getRenderer();
5917
5918                 SALOME_Selection *Sel =
5919                         SALOME_Selection::Selection(myActiveStudy->getSelection());
5920                 int nbSel = Sel->IObjectCount();
5921                 if (nbSel == 0)
5922                 {
5923                         vtkActorCollection *actorList = theRenderer->GetActors();
5924                         actorList->InitTraversal();
5925                         vtkActor *ac = actorList->GetNextActor();
5926                         while (!(ac == NULL))
5927                         {
5928                                 if (ac->IsA("SMESH_Actor"))
5929                                 {
5930                                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
5931                                         if (anActor->hasIO())
5932                                         {
5933                                                 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5934                                                 Update(IO);
5935                                         }
5936                                 }
5937                                 ac = actorList->GetNextActor();
5938                         }
5939                 }
5940                 else
5941                 {
5942                         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
5943                         for (; It.More(); It.Next())
5944                         {
5945                                 Handle(SALOME_InteractiveObject) IO = It.Value();
5946                                 Update(IO);
5947                         }
5948                 }
5949                 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5950                 renWin->Render();
5951         }
5952         QApplication::restoreOverrideCursor();
5953 }
5954
5955 //=============================================================================
5956 /*!
5957  *
5958  */
5959 //=============================================================================
5960 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject) & IO)
5961 {
5962         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5963                 return;
5964
5965         if (IO->hasEntry())
5966         {
5967                 Standard_Boolean res;
5968                 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh(IO, res);
5969                 if (res)
5970                 {
5971                         SMESH_Actor *ac = FindActorByEntry(IO->getEntry(), res, false);
5972                         if (res)
5973                         {
5974                                 // Check whether the actor belongs to the active view
5975                                 VTKViewer_RenderWindowInteractor *rwInter =
5976                                         ((VTKViewer_ViewFrame *) myActiveStudy->
5977                                         getActiveStudyFrame()->getRightFrame()->getViewFrame())->
5978                                         getRWInteractor();
5979
5980                                 ac = ReadScript(aMesh);
5981                                 // The actor belongs to inactive view -> create a copy and display it in the active view
5982                                 if (!rwInter->isInViewer(IO))
5983                                 {
5984                                         SMESH_Actor *acCopy = SMESH_Actor::New();
5985                                         acCopy->ShallowCopy(ac);
5986                                         ac=acCopy;
5987                                 }
5988
5989                                 if (ac != NULL)
5990                                 {
5991 #ifdef TRACE
5992                                         Dump(ac);
5993 #endif
5994                                         DisplayActor(ac);
5995                                         DisplayEdges(ac);
5996                                         smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
5997                                 }
5998                         }
5999                 }
6000         }
6001 }
6002
6003 //=============================================================================
6004 /*!
6005  *
6006  */
6007 //=============================================================================
6008 vtkActor *SMESHGUI::SimulationMoveNode(SMESH_Actor * Mactor, int idnode)
6009 {
6010         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6011                 return NULL;
6012
6013         mySimulationActors = vtkActorCollection::New();
6014         vtkRenderer *theRenderer =
6015                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6016                 getRightFrame()->getViewFrame())->getRenderer();
6017
6018         vtkUnstructuredGrid *ugrid =
6019                 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
6020         vtkIdList *IdCells = vtkIdList::New();
6021         ugrid->GetPointCells(idnode, IdCells);
6022
6023         vtkPoints *Pts = vtkPoints::New();
6024         Pts = ugrid->GetPoints();
6025
6026         vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
6027         ugridSimulation->SetPoints(Pts);
6028         vtkIdList *IdPts = vtkIdList::New();
6029         for (int j = 0; j < IdCells->GetNumberOfIds(); j++)
6030         {
6031                 ugrid->GetCellPoints(IdCells->GetId(j), IdPts);
6032                 ugridSimulation->InsertNextCell(ugrid->GetCellType(IdCells->GetId(j)),
6033                         IdPts);
6034         }
6035
6036         vtkProperty *prop = vtkProperty::New();
6037         prop->SetColor(1., 0., 0.);
6038         prop->SetRepresentationToWireframe();
6039
6040         int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
6041         if (Edgewidth == 0)
6042                 Edgewidth = 1;
6043         prop->SetLineWidth(Edgewidth + 1);
6044
6045         vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6046         Mapper->SetInput(ugridSimulation);
6047         vtkActor *ac = vtkActor::New();
6048         ac->SetMapper(Mapper);
6049         ac->SetProperty(prop);
6050
6051         ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
6052         ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
6053
6054         mySimulationActors->AddItem(ac);
6055         theRenderer->AddActor(ac);
6056
6057         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6058         renWin->Render();
6059
6060         return ac;
6061 }
6062
6063 //=============================================================================
6064 /*!
6065  *
6066  */
6067 //=============================================================================
6068 void SMESHGUI::DisplaySimulationNode(SMESH::SMESH_Mesh_ptr aMesh, float x,
6069         float y, float z)
6070 {
6071         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6072                 return;
6073
6074         EraseSimulationActors();
6075         mySimulationActors = vtkActorCollection::New();
6076         vtkRenderer *theRenderer =
6077                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6078                 getRightFrame()->getViewFrame())->getRenderer();
6079         Standard_Boolean result;
6080         SMESH_Actor *ac = FindActor(aMesh, result, true);
6081
6082         if (result)
6083         {
6084                 vtkUnstructuredGrid *ugrid =
6085                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6086                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6087
6088                 vtkPoints *Pts = ugrid->GetPoints();
6089                 vtkPoints *newPts = vtkPoints::New();
6090                 int nbPts = Pts->GetNumberOfPoints();
6091                 for (int i = 0; i < nbPts; i++)
6092                 {
6093                         newPts->InsertPoint(i, Pts->GetPoint(i));
6094                 }
6095
6096                 newugrid->SetPoints(newPts);
6097                 newugrid->GetPoints()->InsertNextPoint(x, y, z);
6098
6099                 vtkMaskPoints *verts = vtkMaskPoints::New();
6100                 verts->SetInput(newugrid);
6101                 verts->SetGenerateVertices(1);
6102                 verts->SetOnRatio(1);
6103
6104                 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
6105                 vertMapper->SetInput(verts->GetOutput());
6106                 vertMapper->ScalarVisibilityOff();
6107
6108                 vtkActor *node = vtkActor::New();
6109                 node->SetMapper(vertMapper);
6110
6111                 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
6112                 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
6113                 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
6114                 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
6115                 if (!nodecolor.isValid())
6116 //       nodecolor = QColor(0.,1.,0.);
6117                         nodecolor = QColor(0, 1, 0);
6118
6119                 node->GetProperty()->SetColor(float (nodecolor.red()) / 255.,
6120                         float (nodecolor.green()) / 255., float (nodecolor.blue()) / 255.);
6121
6122                 int intValue =
6123                         QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
6124                 if (intValue < 1)
6125                         intValue == 1;
6126
6127                 node->GetProperty()->SetPointSize(intValue);
6128
6129                 node->VisibilityOn();
6130
6131                 mySimulationActors->AddItem(node);
6132                 theRenderer->AddActor(node);
6133         }
6134
6135         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6136         renWin->Render();
6137 }
6138
6139 //=============================================================================
6140 /*!
6141  *
6142  */
6143 //=============================================================================
6144 void SMESHGUI::DisplaySimulationMoveNode(vtkActor * ac, int idnode, float x,
6145         float y, float z)
6146 {
6147         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6148                 return;
6149
6150         vtkRenderer *theRenderer =
6151                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6152                 getRightFrame()->getViewFrame())->getRenderer();
6153         float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
6154         pt[0] = x;
6155         pt[1] = y;
6156         pt[2] = z;
6157
6158         ac->GetMapper()->ImmediateModeRenderingOn();
6159         ac->GetProperty()->SetRepresentationToWireframe();
6160
6161         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6162
6163         renWin->Render();
6164 }
6165
6166 //=============================================================================
6167 /*!
6168  *
6169  */
6170 //=============================================================================
6171 void SMESHGUI::MoveNode(SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x,
6172         float y, float z)
6173 {
6174         Standard_Boolean result;
6175
6176         SMESH_Actor *MeshActor = FindActor(aMesh, result, true);
6177         if (result)
6178         {
6179         }
6180 }
6181
6182 //=============================================================================
6183 /*!
6184  *
6185  */
6186 //=============================================================================
6187 void SMESHGUI::ScalarVisibilityOff()
6188 {
6189         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6190                 return;
6191
6192         vtkRenderer *theRenderer =
6193                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6194                 getRightFrame()->getViewFrame())->getRenderer();
6195         vtkActorCollection *actorList = theRenderer->GetActors();
6196
6197         actorList->InitTraversal();
6198         vtkActor *ac = actorList->GetNextActor();
6199         while (!(ac == NULL))
6200         {
6201                 if (ac->IsA("SMESH_Actor"))
6202                 {
6203                         SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
6204                         if (anActor->GetVisibility() == 1)
6205                         {
6206                                 vtkDataSetMapper *meshMapper =
6207                                         (vtkDataSetMapper *) (anActor->getMapper());
6208                                 meshMapper->ScalarVisibilityOff();
6209                                 meshMapper->SetInput(anActor->DataSource);
6210                                 ChangeRepresentation(anActor, anActor->getDisplayMode());
6211                         }
6212                 }
6213                 ac = actorList->GetNextActor();
6214         }
6215
6216         theRenderer->Render();
6217 }
6218
6219 //=============================================================================
6220 /*!
6221  *
6222  */
6223 //=============================================================================
6224 void SMESHGUI::DisplaySimulationEdge(SMESH::SMESH_Mesh_ptr aMesh,
6225         const TColStd_MapOfInteger & MapIndex)
6226 {
6227         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6228                 return;
6229
6230         EraseSimulationActors();
6231         mySimulationActors = vtkActorCollection::New();
6232         vtkRenderer *theRenderer =
6233                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6234                 getRightFrame()->getViewFrame())->getRenderer();
6235         Standard_Boolean result;
6236         SMESH_Actor *ac = FindActor(aMesh, result, true);
6237         if (result)
6238         {
6239                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6240                 int idNodes[2];
6241                 int pts[2];
6242                 int i = 0;
6243                 vtkIdList *Ids = vtkIdList::New();
6244                 for (; ite.More(); ite.Next())
6245                 {
6246                         idNodes[i] = ite.Key();
6247                         i++;
6248                 }
6249
6250                 Ids->InsertId(0, idNodes[0]);
6251                 pts[0] = idNodes[0];
6252                 Ids->InsertId(1, idNodes[1]);
6253                 pts[1] = idNodes[1];
6254
6255                 vtkUnstructuredGrid *ugrid =
6256                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6257                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6258                 newugrid->SetPoints(ugrid->GetPoints());
6259                 newugrid->InsertNextCell(VTK_LINE, 2, pts);
6260
6261                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6262                 Mapper->SetInput(newugrid);
6263                 Mapper->Update();
6264
6265                 vtkActor *edge = vtkActor::New();
6266                 edge->SetMapper(Mapper);
6267                 edge->SetProperty(ac->GetProperty());
6268                 edge->SetBackfaceProperty(ac->GetBackfaceProperty());
6269                 edge->VisibilityOn();
6270                 mySimulationActors->AddItem(edge);
6271                 theRenderer->AddActor(edge);
6272         }
6273
6274         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6275         renWin->Render();
6276 }
6277
6278 //=============================================================================
6279 /*!
6280  *
6281  */
6282 //=============================================================================
6283 void SMESHGUI::DisplaySimulationTriangle(SMESH::SMESH_Mesh_ptr aMesh,
6284         const TColStd_MapOfInteger & MapIndex, bool reverse)
6285 {
6286         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6287                 return;
6288
6289         EraseSimulationActors();
6290         mySimulationActors = vtkActorCollection::New();
6291         vtkRenderer *theRenderer =
6292                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6293                 getRightFrame()->getViewFrame())->getRenderer();
6294         Standard_Boolean result;
6295         SMESH_Actor *ac = FindActor(aMesh, result, true);
6296         if (result)
6297         {
6298                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6299                 int idNodes[3];
6300                 int pts[3];
6301                 int i = 0;
6302                 vtkIdList *Ids = vtkIdList::New();
6303                 for (; ite.More(); ite.Next())
6304                 {
6305                         idNodes[i] = ite.Key();
6306                         i++;
6307                 }
6308
6309                 if (reverse)
6310                 {
6311                         Ids->InsertId(0, idNodes[2]);
6312                         pts[0] = idNodes[2];
6313                         Ids->InsertId(1, idNodes[1]);
6314                         pts[1] = idNodes[1];
6315                         Ids->InsertId(2, idNodes[0]);
6316                         pts[2] = idNodes[0];
6317                 }
6318                 else
6319                 {
6320                         Ids->InsertId(0, idNodes[0]);
6321                         pts[0] = idNodes[0];
6322                         Ids->InsertId(1, idNodes[1]);
6323                         pts[1] = idNodes[1];
6324                         Ids->InsertId(2, idNodes[2]);
6325                         pts[2] = idNodes[2];
6326                 }
6327                 vtkUnstructuredGrid *ugrid =
6328                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6329                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6330                 newugrid->SetPoints(ugrid->GetPoints());
6331                 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
6332
6333                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6334                 Mapper->SetInput(newugrid);
6335                 Mapper->Update();
6336
6337                 vtkActor *tri = vtkActor::New();
6338                 tri->SetMapper(Mapper);
6339                 tri->SetProperty(ac->GetProperty());
6340                 tri->SetBackfaceProperty(ac->GetBackfaceProperty());
6341                 tri->VisibilityOn();
6342                 mySimulationActors->AddItem(tri);
6343                 theRenderer->AddActor(tri);
6344         }
6345
6346         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6347         renWin->Render();
6348 }
6349
6350 //=============================================================================
6351 /*!
6352  *
6353  */
6354 //=============================================================================
6355 void SMESHGUI::DisplaySimulationQuadrangle(SMESH::SMESH_Mesh_ptr aMesh,
6356         const TColStd_MapOfInteger & MapIndex, bool reverse)
6357 {
6358         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6359                 return;
6360
6361         EraseSimulationActors();
6362         mySimulationActors = vtkActorCollection::New();
6363         vtkRenderer *theRenderer =
6364                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6365                 getRightFrame()->getViewFrame())->getRenderer();
6366         Standard_Boolean result;
6367         SMESH_Actor *ac = FindActor(aMesh, result, true);
6368
6369         vtkUnstructuredGrid *ugrid =
6370                 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6371
6372         if (result)
6373         {
6374                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6375                 int i = 0;
6376                 int idNodes[4];
6377                 vtkIdList *Ids = vtkIdList::New();
6378                 for (; ite.More(); ite.Next())
6379                 {
6380                         idNodes[i] = ite.Key();
6381                         i++;
6382                 }
6383
6384                 float *p0 = ugrid->GetPoint(idNodes[0]);
6385                 float *p1 = ugrid->GetPoint(idNodes[1]);
6386                 float *p2 = ugrid->GetPoint(idNodes[2]);
6387                 float *p3 = ugrid->GetPoint(idNodes[3]);
6388
6389                 gp_Pnt P0(p0[0], p0[1], p0[2]);
6390
6391                 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6392                 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6393                 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6394
6395                 gp_Vec Cross1 = V1 ^ V2;
6396                 gp_Vec Cross2 = V2 ^ V3;
6397
6398                 int tmp;
6399                 if (Cross1.Dot(Cross2) < 0)
6400                 {
6401                         V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6402                         V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6403                         Cross1 = V1 ^ V2;
6404                         Cross2 = V2 ^ V3;
6405
6406                         if (Cross1.Dot(Cross2) < 0)
6407                         {
6408                                 tmp = idNodes[2];
6409                                 idNodes[2] = idNodes[3];
6410                                 idNodes[3] = tmp;
6411                         }
6412                         else
6413                         {
6414                                 tmp = idNodes[1];
6415                                 idNodes[1] = idNodes[2];
6416                                 idNodes[2] = tmp;
6417                         }
6418                 }
6419
6420                 if (reverse)
6421                 {
6422                         Ids->InsertId(0, idNodes[3]);
6423                         Ids->InsertId(1, idNodes[2]);
6424                         Ids->InsertId(2, idNodes[1]);
6425                         Ids->InsertId(3, idNodes[0]);
6426                 }
6427                 else
6428                 {
6429                         Ids->InsertId(0, idNodes[0]);
6430                         Ids->InsertId(1, idNodes[1]);
6431                         Ids->InsertId(2, idNodes[2]);
6432                         Ids->InsertId(3, idNodes[3]);
6433                 }
6434
6435                 //    vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
6436                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6437                 newugrid->SetPoints(ugrid->GetPoints());
6438                 newugrid->InsertNextCell(VTK_QUAD, Ids);
6439
6440                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6441                 Mapper->SetInput(newugrid);
6442                 Mapper->Update();
6443
6444                 vtkActor *quad = vtkActor::New();
6445                 quad->SetMapper(Mapper);
6446                 quad->SetProperty(ac->GetProperty());
6447                 quad->SetBackfaceProperty(ac->GetBackfaceProperty());
6448                 quad->VisibilityOn();
6449                 mySimulationActors->AddItem(quad);
6450                 theRenderer->AddActor(quad);
6451         }
6452         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6453         renWin->Render();
6454 }
6455
6456 //=============================================================================
6457 /*!
6458  *
6459  */
6460 //=============================================================================
6461 void SMESHGUI::DisplaySimulationTetra(SMESH::SMESH_Mesh_ptr aMesh,
6462         const TColStd_MapOfInteger & MapIndex)
6463 {
6464         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6465                 return;
6466
6467         EraseSimulationActors();
6468         mySimulationActors = vtkActorCollection::New();
6469         vtkRenderer *theRenderer =
6470                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6471                 getRightFrame()->getViewFrame())->getRenderer();
6472         Standard_Boolean result;
6473         SMESH_Actor *ac = FindActor(aMesh, result, true);
6474         if (result)
6475         {
6476                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6477                 int i = 0;
6478                 int idNodes[4];
6479                 vtkIdList *Ids = vtkIdList::New();
6480                 for (; ite.More(); ite.Next())
6481                 {
6482                         idNodes[i] = ite.Key();
6483                         i++;
6484                 }
6485
6486                 Ids->InsertId(0, idNodes[0]);
6487                 Ids->InsertId(1, idNodes[1]);
6488                 Ids->InsertId(2, idNodes[2]);
6489                 Ids->InsertId(3, idNodes[3]);
6490
6491                 vtkUnstructuredGrid *ugrid =
6492                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6493                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6494                 newugrid->SetPoints(ugrid->GetPoints());
6495                 newugrid->InsertNextCell(VTK_TETRA, Ids);
6496
6497                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6498                 Mapper->SetInput(newugrid);
6499                 Mapper->Update();
6500
6501                 vtkActor *tetra = vtkActor::New();
6502                 tetra->SetMapper(Mapper);
6503                 tetra->SetProperty(ac->GetProperty());
6504                 tetra->SetBackfaceProperty(ac->GetBackfaceProperty());
6505                 tetra->VisibilityOn();
6506                 mySimulationActors->AddItem(tetra);
6507                 theRenderer->AddActor(tetra);
6508         }
6509         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6510         renWin->Render();
6511 }
6512
6513 //=============================================================================
6514 /*!
6515  *
6516  */
6517 //=============================================================================
6518 void SMESHGUI::DisplaySimulationHexa(SMESH::SMESH_Mesh_ptr aMesh,
6519         const TColStd_MapOfInteger & MapIndex)
6520 {
6521         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6522                 return;
6523
6524         EraseSimulationActors();
6525         mySimulationActors = vtkActorCollection::New();
6526         vtkRenderer *theRenderer =
6527                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6528                 getRightFrame()->getViewFrame())->getRenderer();
6529         Standard_Boolean result;
6530         SMESH_Actor *ac = FindActor(aMesh, result, true);
6531         if (result)
6532         {
6533                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6534                 int i = 0;
6535                 int idNodes[8];
6536                 vtkIdList *Ids = vtkIdList::New();
6537                 for (; ite.More(); ite.Next())
6538                 {
6539                         idNodes[i] = ite.Key();
6540                         i++;
6541                 }
6542
6543                 Ids->InsertId(0, idNodes[0]);
6544                 Ids->InsertId(1, idNodes[1]);
6545                 Ids->InsertId(2, idNodes[2]);
6546                 Ids->InsertId(3, idNodes[3]);
6547                 Ids->InsertId(4, idNodes[4]);
6548                 Ids->InsertId(5, idNodes[5]);
6549                 Ids->InsertId(6, idNodes[6]);
6550                 Ids->InsertId(7, idNodes[7]);
6551
6552                 vtkUnstructuredGrid *ugrid =
6553                         vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6554                 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6555                 newugrid->SetPoints(ugrid->GetPoints());
6556                 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
6557
6558                 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6559                 Mapper->SetInput(newugrid);
6560                 Mapper->Update();
6561
6562                 vtkActor *hexa = vtkActor::New();
6563                 hexa->SetMapper(Mapper);
6564                 hexa->SetProperty(ac->GetProperty());
6565                 hexa->SetBackfaceProperty(ac->GetBackfaceProperty());
6566                 hexa->VisibilityOn();
6567                 mySimulationActors->AddItem(hexa);
6568                 theRenderer->AddActor(hexa);
6569         }
6570         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6571         renWin->Render();
6572 }
6573
6574 //=============================================================================
6575 /*!
6576  *
6577  */
6578 //=============================================================================
6579 void SMESHGUI::AddFace(SMESH::SMESH_Mesh_ptr aMesh,
6580         const TColStd_MapOfInteger & MapIndex, bool reverse)
6581 {
6582         QApplication::setOverrideCursor(Qt::waitCursor);
6583         Standard_Boolean result;
6584         SMESH_Actor *ac = FindActor(aMesh, result, true);
6585         if (result)
6586         {
6587                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6588                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6589                 anArrayOfIdeces->length(MapIndex.Extent());
6590
6591                 int i = 0;
6592                 for (; ite.More(); ite.Next())
6593                 {
6594                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6595                         i++;
6596                 }
6597
6598                 int tmp;
6599                 if (MapIndex.Extent() == 4)
6600                 {
6601                         int idNodes[4];
6602                         int i = 0;
6603                         TColStd_MapIteratorOfMapOfInteger ite1(MapIndex);
6604                         for (; ite1.More(); ite1.Next())
6605                         {
6606                                 idNodes[i] = ite1.Key();
6607                                 i++;
6608                         }
6609
6610                         vtkUnstructuredGrid *ugrid =
6611                                 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6612                         float *p0 = ugrid->GetPoint(idNodes[0]);
6613                         float *p1 = ugrid->GetPoint(idNodes[1]);
6614                         float *p2 = ugrid->GetPoint(idNodes[2]);
6615                         float *p3 = ugrid->GetPoint(idNodes[3]);
6616
6617                         gp_Pnt P0(p0[0], p0[1], p0[2]);
6618
6619                         gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6620                         gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6621                         gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6622
6623                         gp_Vec Cross1 = V1 ^ V2;
6624                         gp_Vec Cross2 = V2 ^ V3;
6625
6626                         if (Cross1.Dot(Cross2) < 0)
6627                         {
6628
6629                                 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6630                                 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6631                                 Cross1 = V1 ^ V2;
6632                                 Cross2 = V2 ^ V3;
6633
6634                                 if (Cross1.Dot(Cross2) < 0)
6635                                 {
6636                                         tmp = anArrayOfIdeces[2];
6637                                         anArrayOfIdeces[2] = anArrayOfIdeces[3];
6638                                         anArrayOfIdeces[3] = tmp;
6639                                 }
6640                                 else
6641                                 {
6642                                         tmp = anArrayOfIdeces[1];
6643                                         anArrayOfIdeces[1] = anArrayOfIdeces[2];
6644                                         anArrayOfIdeces[2] = tmp;
6645                                 }
6646                         }
6647                 }
6648
6649                 //    int tmp;
6650                 if (reverse)
6651                 {
6652                         for (i = 0; i < (MapIndex.Extent() / 2); i++)
6653                         {
6654                                 tmp = anArrayOfIdeces[i];
6655                                 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent() - i - 1];
6656                                 anArrayOfIdeces[MapIndex.Extent() - i - 1] = tmp;
6657                         }
6658                 }
6659                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6660                 aMeshEditor->AddFace(anArrayOfIdeces);
6661         }
6662         if (myAutomaticUpdate)
6663         {
6664                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6665                 if (Mesh != NULL)
6666                 {
6667                         smeshGUI->DisplayActor(Mesh);
6668                         smeshGUI->DisplayEdges(Mesh);
6669                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6670                         AddActorInSelection(Mesh);
6671                 }
6672         }
6673         QApplication::restoreOverrideCursor();
6674 }
6675
6676 //=============================================================================
6677 /*!
6678  *
6679  */
6680 //=============================================================================
6681 void SMESHGUI::AddVolume(SMESH::SMESH_Mesh_ptr aMesh,
6682         const TColStd_MapOfInteger & MapIndex)
6683 {
6684         QApplication::setOverrideCursor(Qt::waitCursor);
6685         Standard_Boolean result;
6686         SMESH_Actor *ac = FindActor(aMesh, result, true);
6687         if (result)
6688         {
6689                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6690                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6691                 anArrayOfIdeces->length(MapIndex.Extent());
6692
6693                 int i = 0;
6694                 for (; ite.More(); ite.Next())
6695                 {
6696                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6697                         i++;
6698                 }
6699
6700                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6701                 aMeshEditor->AddVolume(anArrayOfIdeces);
6702         }
6703         if (myAutomaticUpdate)
6704         {
6705                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6706                 if (Mesh != NULL)
6707                 {
6708                         smeshGUI->DisplayActor(Mesh);
6709                         smeshGUI->DisplayEdges(Mesh);
6710                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6711                         AddActorInSelection(Mesh);
6712                 }
6713         }
6714         QApplication::restoreOverrideCursor();
6715 }
6716
6717 //=============================================================================
6718 /*!
6719  *
6720  */
6721 //=============================================================================
6722 void SMESHGUI::AddEdge(SMESH::SMESH_Mesh_ptr aMesh,
6723         const TColStd_MapOfInteger & MapIndex)
6724 {
6725         QApplication::setOverrideCursor(Qt::waitCursor);
6726         Standard_Boolean result;
6727         SMESH_Actor *ac = FindActor(aMesh, result, true);
6728         if (result)
6729         {
6730                 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6731                 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6732                 anArrayOfIdeces->length(MapIndex.Extent());
6733
6734                 int i = 0;
6735                 for (; ite.More(); ite.Next())
6736                 {
6737                         anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6738                         i++;
6739                 }
6740
6741                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6742                 aMeshEditor->AddEdge(anArrayOfIdeces);
6743         }
6744         if (myAutomaticUpdate)
6745         {
6746                 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6747                 if (Mesh != NULL)
6748                 {
6749                         smeshGUI->DisplayActor(Mesh);
6750                         smeshGUI->DisplayEdges(Mesh);
6751                         smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6752                         AddActorInSelection(Mesh);
6753                 }
6754         }
6755         QApplication::restoreOverrideCursor();
6756 }
6757
6758 //=============================================================================
6759 /*!
6760  *
6761  */
6762 //=============================================================================
6763 void SMESHGUI::AddNode(SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
6764 {
6765         QApplication::setOverrideCursor(Qt::waitCursor);
6766         Standard_Boolean result;
6767         SMESH_Actor *ac = FindActor(aMesh, result, true);
6768         if (result)
6769         {
6770                 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6771                 aMeshEditor->AddNode(x, y, z);
6772
6773                 if (myAutomaticUpdate)
6774                 {
6775                         SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6776                         if (Mesh != NULL)
6777                         {
6778                                 smeshGUI->DisplayActor(Mesh);
6779                                 smeshGUI->DisplayEdges(Mesh);
6780                                 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6781                                 AddActorInSelection(Mesh);
6782                         }
6783                 }
6784         }
6785         QApplication::restoreOverrideCursor();
6786 }
6787
6788 //=============================================================================
6789 /*!
6790  *
6791  */
6792 //=============================================================================
6793 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor * ac)
6794 {
6795         if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6796                 return;
6797
6798         EraseSimulationActors();
6799         mySimulationActors2D = vtkActor2DCollection::New();
6800
6801         vtkRenderer *theRenderer =
6802                 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6803                 getRightFrame()->getViewFrame())->getRenderer();
6804
6805         vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
6806         gs2->SetGlyphTypeToTriangle();
6807         gs2->FilledOff();
6808
6809         vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
6810         legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
6811         legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.);       //relative to Position
6812
6813         legend->SetNumberOfEntries(4);
6814         legend->SetEntryString(0, tr("SMESH_BOUNDARYEDGES"));
6815         legend->SetEntrySymbol(0, gs2->GetOutput());
6816         legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.));
6817         legend->SetEntryString(1, tr("SMESH_MANIFOLDEDGES"));
6818         legend->SetEntrySymbol(1, gs2->GetOutput());
6819         legend->SetEntryColor(1,
6820                 ac->GetMapper()->GetLookupTable()->GetColor(0.666667));
6821         legend->SetEntryString(2, tr("SMESH_NONMANIFOLDEDGES"));
6822         legend->SetEntrySymbol(2, gs2->GetOutput());
6823         legend->SetEntryColor(2,
6824                 ac->GetMapper()->GetLookupTable()->GetColor(0.222222));
6825         legend->SetEntryString(3, tr("SMESH_FEATUREEDGES"));
6826         legend->SetEntrySymbol(3, gs2->GetOutput());
6827         legend->SetEntryColor(3,
6828                 ac->GetMapper()->GetLookupTable()->GetColor(0.444444));
6829         legend->SetPadding(5);
6830         //  legend->GetProperty()->SetColor();
6831
6832         mySimulationActors2D->AddItem(legend);
6833         theRenderer->AddActor2D(legend);
6834
6835         // Update the view
6836         myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->
6837                 Repaint();
6838 }
6839
6840 //===============================================================================
6841 // function : OnEditDelete()
6842 // purpose  :
6843 //===============================================================================
6844 void SMESHGUI::OnEditDelete()
6845 {
6846         if (QAD_MessageBox::warn2
6847                 (QAD_Application::getDesktop(),
6848                         tr("SMESH_WRN_WARNING"),
6849                         tr("SMESH_REALLY_DELETE"),
6850                         tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
6851                 return;
6852
6853         int nbSf = myActiveStudy->getStudyFramesCount();
6854
6855         Standard_Boolean found;
6856         SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
6857         SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
6858         SALOMEDS::GenericAttribute_var anAttr;
6859         SALOMEDS::AttributeIOR_var anIOR;
6860
6861         SALOME_Selection *Sel =
6862                 SALOME_Selection::Selection(myActiveStudy->getSelection());
6863         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
6864         for (; It.More(); It.Next())
6865         {
6866                 Handle(SALOME_InteractiveObject) IObject = It.Value();
6867                 if (IObject->hasEntry())
6868                 {
6869                         SALOMEDS::SObject_var SO =
6870                                 myStudy->FindObjectID(IObject->getEntry());
6871
6872                         /* Erase child graphical objects */
6873                         SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
6874                         for (; it->More(); it->Next())
6875                         {
6876                                 SALOMEDS::SObject_var CSO = it->Value();
6877                                 if (CSO->FindAttribute(anAttr, "AttributeIOR"))
6878                                 {
6879                                         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6880
6881                                         for (int i = 0; i < nbSf; i++)
6882                                         {
6883                                                 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
6884                                                 if (sf->getTypeView() == VIEW_VTK)
6885                                                 {
6886                                                         vtkRenderer *Renderer =
6887                                                                 ((VTKViewer_ViewFrame *) smeshGUI->
6888                                                                 myActiveStudy->getActiveStudyFrame()->
6889                                                                 getRightFrame()->getViewFrame())->getRenderer();
6890                                                         SMESH_Actor *ac =
6891                                                                 smeshGUI->FindActorByEntry(CSO->GetID(), found,
6892                                                                 false);
6893                                                         if (found)
6894                                                         {
6895                                                                 Renderer->RemoveActor(ac->EdgeDevice);
6896                                                                 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6897                                                                 Renderer->RemoveActor(ac);
6898                                                         }
6899                                                 }
6900                                         }
6901                                 }
6902                         }
6903
6904                         /* Erase main graphical object */
6905                         for (int i = 0; i < nbSf; i++)
6906                         {
6907                                 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
6908                                 if (sf->getTypeView() == VIEW_VTK)
6909                                 {
6910                                         vtkRenderer *Renderer =
6911                                                 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
6912                                                 getActiveStudyFrame()->getRightFrame()->
6913                                                 getViewFrame())->getRenderer();
6914                                         VTKViewer_RenderWindowInteractor *myRenderInter =
6915                                                 ((VTKViewer_ViewFrame *) sf->getRightFrame()->
6916                                                 getViewFrame())->getRWInteractor();
6917                                         SMESH_Actor *ac =
6918                                                 smeshGUI->FindActorByEntry(IObject->getEntry(), found,
6919                                                 false);
6920                                         if (found)
6921                                         {
6922                                                 Renderer->RemoveActor(ac->EdgeDevice);
6923                                                 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6924                                         }
6925                                         myRenderInter->Remove(IObject);
6926                                 }
6927                         }
6928
6929                         /* Erase objects in Study */
6930                         SALOMEDS::SObject_var obj =
6931                                 myStudy->FindObjectID(IObject->getEntry());
6932                         if (!obj->_is_nil())
6933                         {
6934                                 QAD_Operation *op =
6935                                         new SALOMEGUI_ImportOperation(myActiveStudy);
6936                                 op->start();
6937                                 aStudyBuilder->RemoveObject(obj);
6938                                 op->finish();
6939                         }
6940
6941                 }                                               /* IObject->hasEntry() */
6942         }                                                       /* more/next           */
6943
6944         /* Clear any previous selection */
6945         Sel->ClearIObjects();
6946         myActiveStudy->updateObjBrowser();
6947 }