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